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" 282c65db5eSPaolo Bonzini #include "qemu/datadir.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" 400d09e41aSPaolo Bonzini #include "hw/nvram/fw_cfg.h" 410d09e41aSPaolo Bonzini #include "hw/char/escc.h" 42e1218e48SMark Cave-Ayland #include "hw/misc/macio/macio.h" 43baec1910SAndreas Färber #include "hw/loader.h" 44bbcc635fSMark Cave-Ayland #include "hw/fw-path-provider.h" 45ca20cf32SBlue Swirl #include "elf.h" 46c525436eSMarkus Armbruster #include "qemu/error-report.h" 479c17d615SPaolo Bonzini #include "sysemu/kvm.h" 4871e8a915SMarkus Armbruster #include "sysemu/reset.h" 49dc333cd6SAlexander Graf #include "kvm_ppc.h" 503cbee15bSj_mayer 51e4bcb14cSths #define MAX_IDE_BUS 2 52271dd5e0Sblueswir1 #define CFG_ADDR 0xf0000510 53536d8cdaSAlexander Graf #define TBFREQ 16600000UL 549d1c1283SBALATON Zoltan #define CLOCKFREQ 266000000UL 559d1c1283SBALATON Zoltan #define BUSFREQ 66000000UL 56271dd5e0Sblueswir1 57b50de5cdSMark Cave-Ayland #define NDRV_VGA_FILENAME "qemu_vga.ndrv" 58b50de5cdSMark Cave-Ayland 59a773e64aSMark Cave-Ayland #define GRACKLE_BASE 0xfec00000 60464c73e8SBALATON Zoltan #define PROM_BASE 0xffc00000 61464c73e8SBALATON Zoltan #define PROM_SIZE (4 * MiB) 62a773e64aSMark Cave-Ayland 63ddcd5531SGonglei static void fw_cfg_boot_set(void *opaque, const char *boot_device, 64ddcd5531SGonglei Error **errp) 65513f789fSblueswir1 { 6648779e50SGabriel L. Somlo fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); 67513f789fSblueswir1 } 68513f789fSblueswir1 69409dbce5SAurelien Jarno static uint64_t translate_kernel_address(void *opaque, uint64_t addr) 70409dbce5SAurelien Jarno { 71409dbce5SAurelien Jarno return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR; 72409dbce5SAurelien Jarno } 73409dbce5SAurelien Jarno 741bba0dc9SAndreas Färber static void ppc_heathrow_reset(void *opaque) 751bba0dc9SAndreas Färber { 76cd79664fSAndreas Färber PowerPCCPU *cpu = opaque; 771bba0dc9SAndreas Färber 78cd79664fSAndreas Färber cpu_reset(CPU(cpu)); 791bba0dc9SAndreas Färber } 801bba0dc9SAndreas Färber 813ef96221SMarcel Apfelbaum static void ppc_heathrow_init(MachineState *machine) 823cbee15bSj_mayer { 833ef96221SMarcel Apfelbaum ram_addr_t ram_size = machine->ram_size; 84cd7b9498SPaolo Bonzini const char *bios_name = machine->firmware ?: PROM_FILENAME; 8597ec4d21SPaolo Bonzini const char *boot_device = machine->boot_config.order; 8672c33dd7SAndreas Färber PowerPCCPU *cpu = NULL; 87e2684c0bSAndreas Färber CPUPPCState *env = NULL; 885cea8590SPaul Brook char *filename; 89b8df3255SBALATON Zoltan int i; 90c92bb2c7SAvi Kivity MemoryRegion *bios = g_new(MemoryRegion, 1); 91b9e17a34SAlexander Graf uint32_t kernel_base, initrd_base, cmdline_base = 0; 927373048cSblueswir1 int32_t kernel_size, initrd_size; 933cbee15bSj_mayer PCIBus *pci_bus; 947d612261SMarkus Armbruster PCIDevice *macio; 9507a7484eSAndreas Färber MACIOIDEState *macio_ide; 96348b8d1aSMark Cave-Ayland ESCCState *escc; 97a773e64aSMark Cave-Ayland SysBusDevice *s; 98370022ceSMark Cave-Ayland DeviceState *dev, *pic_dev, *grackle_dev; 99293c867dSAndreas Färber BusState *adb_bus; 100464c73e8SBALATON Zoltan uint64_t bios_addr; 1019776874fSPeter Maydell int bios_size; 102fe6b6346SLike Xu unsigned int smp_cpus = machine->smp.cpus; 103513f789fSblueswir1 uint16_t ppc_boot_device; 104f455e98cSGerd Hoffmann DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 105271dd5e0Sblueswir1 void *fw_cfg; 106caae6c96SAlexander Graf uint64_t tbfreq; 1073cbee15bSj_mayer 1083cbee15bSj_mayer /* init CPUs */ 1093cbee15bSj_mayer for (i = 0; i < smp_cpus; i++) { 110f4c6604eSIgor Mammedov cpu = POWERPC_CPU(cpu_create(machine->cpu_type)); 11172c33dd7SAndreas Färber env = &cpu->env; 11272c33dd7SAndreas Färber 113b0fb43d8Saurel32 /* Set time-base frequency to 16.6 Mhz */ 114536d8cdaSAlexander Graf cpu_ppc_tb_init(env, TBFREQ); 115cd79664fSAndreas Färber qemu_register_reset(ppc_heathrow_reset, cpu); 1163cbee15bSj_mayer } 1173cbee15bSj_mayer 1183cbee15bSj_mayer /* allocate RAM */ 119ab3dd749SPhilippe Mathieu-Daudé if (ram_size > 2047 * MiB) { 120ab3dd749SPhilippe Mathieu-Daudé error_report("Too much memory for this machine: %" PRId64 " MB, " 121ab3dd749SPhilippe Mathieu-Daudé "maximum 2047 MB", ram_size / MiB); 1226b4079f8Saurel32 exit(1); 1236b4079f8Saurel32 } 1246b4079f8Saurel32 125c3481ab0SBALATON Zoltan memory_region_add_subregion(get_system_memory(), 0, machine->ram); 126a748ab6dSaurel32 127464c73e8SBALATON Zoltan /* allocate and load firmware ROM */ 128464c73e8SBALATON Zoltan memory_region_init_rom(bios, NULL, "ppc_heathrow.bios", PROM_SIZE, 129f8ed85acSMarkus Armbruster &error_fatal); 130c3481ab0SBALATON Zoltan memory_region_add_subregion(get_system_memory(), PROM_BASE, bios); 131e206ad48SHu Tao 1325cea8590SPaul Brook filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); 1335cea8590SPaul Brook if (filename) { 134464c73e8SBALATON Zoltan /* Load OpenBIOS (ELF) */ 135464c73e8SBALATON Zoltan bios_size = load_elf(filename, NULL, NULL, NULL, NULL, &bios_addr, 136464c73e8SBALATON Zoltan NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0); 137464c73e8SBALATON Zoltan /* Unfortunately, load_elf sign-extends reading elf32 */ 138464c73e8SBALATON Zoltan bios_addr = (uint32_t)bios_addr; 139464c73e8SBALATON Zoltan 140464c73e8SBALATON Zoltan if (bios_size <= 0) { 141b8df3255SBALATON Zoltan /* or if could not load ELF try loading a binary ROM image */ 142464c73e8SBALATON Zoltan bios_size = load_image_targphys(filename, PROM_BASE, PROM_SIZE); 143464c73e8SBALATON Zoltan bios_addr = PROM_BASE; 144464c73e8SBALATON Zoltan } 1457267c094SAnthony Liguori g_free(filename); 1465cea8590SPaul Brook } else { 1475cea8590SPaul Brook bios_size = -1; 1485cea8590SPaul Brook } 149464c73e8SBALATON Zoltan if (bios_size < 0 || bios_addr - PROM_BASE + bios_size > PROM_SIZE) { 150c525436eSMarkus Armbruster error_report("could not load PowerPC bios '%s'", bios_name); 1513cbee15bSj_mayer exit(1); 1523cbee15bSj_mayer } 1533cbee15bSj_mayer 154b8df3255SBALATON Zoltan if (machine->kernel_filename) { 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; 163b8df3255SBALATON Zoltan kernel_size = load_elf(machine->kernel_filename, NULL, 164617160c9SBALATON Zoltan translate_kernel_address, NULL, NULL, NULL, 165617160c9SBALATON Zoltan NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0); 16652f163b7Sblueswir1 if (kernel_size < 0) 167b8df3255SBALATON Zoltan kernel_size = load_aout(machine->kernel_filename, kernel_base, 168ca20cf32SBlue Swirl ram_size - kernel_base, bswap_needed, 169ca20cf32SBlue Swirl TARGET_PAGE_SIZE); 17052f163b7Sblueswir1 if (kernel_size < 0) 171b8df3255SBALATON Zoltan kernel_size = load_image_targphys(machine->kernel_filename, 17252f163b7Sblueswir1 kernel_base, 17352f163b7Sblueswir1 ram_size - kernel_base); 1743cbee15bSj_mayer if (kernel_size < 0) { 175b8df3255SBALATON Zoltan error_report("could not load kernel '%s'", 176b8df3255SBALATON Zoltan machine->kernel_filename); 1773cbee15bSj_mayer exit(1); 1783cbee15bSj_mayer } 1793cbee15bSj_mayer /* load initrd */ 180b8df3255SBALATON Zoltan if (machine->initrd_filename) { 181b8df3255SBALATON Zoltan initrd_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + 182b8df3255SBALATON Zoltan KERNEL_GAP); 183b8df3255SBALATON Zoltan initrd_size = load_image_targphys(machine->initrd_filename, 184b8df3255SBALATON Zoltan initrd_base, 185dcac9679Spbrook ram_size - initrd_base); 1863cbee15bSj_mayer if (initrd_size < 0) { 187c525436eSMarkus Armbruster error_report("could not load initial ram disk '%s'", 188b8df3255SBALATON Zoltan machine->initrd_filename); 1893cbee15bSj_mayer exit(1); 1903cbee15bSj_mayer } 19139d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size); 1923cbee15bSj_mayer } else { 1933cbee15bSj_mayer initrd_base = 0; 1943cbee15bSj_mayer initrd_size = 0; 19539d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP); 1963cbee15bSj_mayer } 1976ac0e82dSbalrog ppc_boot_device = 'm'; 1983cbee15bSj_mayer } else { 1993cbee15bSj_mayer kernel_base = 0; 2003cbee15bSj_mayer kernel_size = 0; 2013cbee15bSj_mayer initrd_base = 0; 2023cbee15bSj_mayer initrd_size = 0; 20328c5af54Sj_mayer ppc_boot_device = '\0'; 2040d913fdbSj_mayer for (i = 0; boot_device[i] != '\0'; i++) { 20528c5af54Sj_mayer /* TOFIX: for now, the second IDE channel is not properly 2060d913fdbSj_mayer * used by OHW. The Mac floppy disk are not emulated. 20728c5af54Sj_mayer * For now, OHW cannot boot from the network. 20828c5af54Sj_mayer */ 20928c5af54Sj_mayer #if 0 2100d913fdbSj_mayer if (boot_device[i] >= 'a' && boot_device[i] <= 'f') { 2110d913fdbSj_mayer ppc_boot_device = boot_device[i]; 21228c5af54Sj_mayer break; 2130d913fdbSj_mayer } 21428c5af54Sj_mayer #else 2150d913fdbSj_mayer if (boot_device[i] >= 'c' && boot_device[i] <= 'd') { 2160d913fdbSj_mayer ppc_boot_device = boot_device[i]; 21728c5af54Sj_mayer break; 2180d913fdbSj_mayer } 21928c5af54Sj_mayer #endif 22028c5af54Sj_mayer } 22128c5af54Sj_mayer if (ppc_boot_device == '\0') { 2226f76b817SAlistair Francis error_report("No valid boot device for G3 Beige machine"); 22328c5af54Sj_mayer exit(1); 22428c5af54Sj_mayer } 2253cbee15bSj_mayer } 2263cbee15bSj_mayer 227370022ceSMark Cave-Ayland /* Timebase Frequency */ 228370022ceSMark Cave-Ayland if (kvm_enabled()) { 229370022ceSMark Cave-Ayland tbfreq = kvmppc_get_tbfreq(); 230370022ceSMark Cave-Ayland } else { 231370022ceSMark Cave-Ayland tbfreq = TBFREQ; 232370022ceSMark Cave-Ayland } 233370022ceSMark Cave-Ayland 23449ac51aeSMark Cave-Ayland /* Grackle PCI host bridge */ 235370022ceSMark Cave-Ayland grackle_dev = qdev_new(TYPE_GRACKLE_PCI_HOST_BRIDGE); 236370022ceSMark Cave-Ayland qdev_prop_set_uint32(grackle_dev, "ofw-addr", 0x80000000); 237370022ceSMark Cave-Ayland s = SYS_BUS_DEVICE(grackle_dev); 23849ac51aeSMark Cave-Ayland sysbus_realize_and_unref(s, &error_fatal); 23949ac51aeSMark Cave-Ayland 24049ac51aeSMark Cave-Ayland sysbus_mmio_map(s, 0, GRACKLE_BASE); 24149ac51aeSMark Cave-Ayland sysbus_mmio_map(s, 1, GRACKLE_BASE + 0x200000); 24249ac51aeSMark Cave-Ayland /* PCI hole */ 24349ac51aeSMark Cave-Ayland memory_region_add_subregion(get_system_memory(), 0x80000000ULL, 24449ac51aeSMark Cave-Ayland sysbus_mmio_get_region(s, 2)); 24549ac51aeSMark Cave-Ayland /* Register 2 MB of ISA IO space */ 24649ac51aeSMark Cave-Ayland memory_region_add_subregion(get_system_memory(), 0xfe000000, 24749ac51aeSMark Cave-Ayland sysbus_mmio_get_region(s, 3)); 24849ac51aeSMark Cave-Ayland 249370022ceSMark Cave-Ayland pci_bus = PCI_HOST_BRIDGE(grackle_dev)->bus; 250370022ceSMark Cave-Ayland 251370022ceSMark Cave-Ayland /* MacIO */ 252370022ceSMark Cave-Ayland macio = pci_new(PCI_DEVFN(16, 0), TYPE_OLDWORLD_MACIO); 253370022ceSMark Cave-Ayland dev = DEVICE(macio); 254370022ceSMark Cave-Ayland qdev_prop_set_uint64(dev, "frequency", tbfreq); 255370022ceSMark Cave-Ayland 256370022ceSMark Cave-Ayland escc = ESCC(object_resolve_path_component(OBJECT(macio), "escc")); 257370022ceSMark Cave-Ayland qdev_prop_set_chr(DEVICE(escc), "chrA", serial_hd(0)); 258370022ceSMark Cave-Ayland qdev_prop_set_chr(DEVICE(escc), "chrB", serial_hd(1)); 259370022ceSMark Cave-Ayland 260370022ceSMark Cave-Ayland pci_realize_and_unref(macio, pci_bus, &error_fatal); 261370022ceSMark Cave-Ayland 262370022ceSMark Cave-Ayland pic_dev = DEVICE(object_resolve_path_component(OBJECT(macio), "pic")); 263370022ceSMark Cave-Ayland for (i = 0; i < 4; i++) { 264370022ceSMark Cave-Ayland qdev_connect_gpio_out(grackle_dev, i, 265370022ceSMark Cave-Ayland qdev_get_gpio_in(pic_dev, 0x15 + i)); 266370022ceSMark Cave-Ayland } 267a5ed75feSMark Cave-Ayland 2683cbee15bSj_mayer /* Connect the heathrow PIC outputs to the 6xx bus */ 2693cbee15bSj_mayer for (i = 0; i < smp_cpus; i++) { 2703cbee15bSj_mayer switch (PPC_INPUT(env)) { 2713cbee15bSj_mayer case PPC_FLAGS_INPUT_6xx: 272370022ceSMark Cave-Ayland /* XXX: we register only 1 output pin for heathrow PIC */ 273a5ed75feSMark Cave-Ayland qdev_connect_gpio_out(pic_dev, 0, 274*0f3e0c6fSCédric Le Goater qdev_get_gpio_in(DEVICE(cpu), PPC6xx_INPUT_INT)); 2753cbee15bSj_mayer break; 2763cbee15bSj_mayer default: 277c525436eSMarkus Armbruster error_report("Bus model not supported on OldWorld Mac machine"); 278c525436eSMarkus Armbruster exit(1); 2793cbee15bSj_mayer } 2803cbee15bSj_mayer } 2813cbee15bSj_mayer 2823e20ad3aSAurelien Jarno pci_vga_init(pci_bus); 2833cbee15bSj_mayer 284343bd85aSMark Cave-Ayland for (i = 0; i < nb_nics; i++) { 28529b358f9SDavid Gibson pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); 286343bd85aSMark Cave-Ayland } 287e4bcb14cSths 288370022ceSMark Cave-Ayland /* MacIO IDE */ 289d8f94e1bSJohn Snow ide_drive_get(hd, ARRAY_SIZE(hd)); 29007a7484eSAndreas Färber macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), 29114eefd0eSAlexander Graf "ide[0]")); 29207a7484eSAndreas Färber macio_ide_init_drives(macio_ide, hd); 29307a7484eSAndreas Färber 29414eefd0eSAlexander Graf macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), 29514eefd0eSAlexander Graf "ide[1]")); 29614eefd0eSAlexander Graf macio_ide_init_drives(macio_ide, &hd[MAX_IDE_DEVS]); 2973cbee15bSj_mayer 298370022ceSMark Cave-Ayland /* MacIO CUDA/ADB */ 299293c867dSAndreas Färber dev = DEVICE(object_resolve_path_component(OBJECT(macio), "cuda")); 300293c867dSAndreas Färber adb_bus = qdev_get_child_bus(dev, "adb.0"); 3013e80f690SMarkus Armbruster dev = qdev_new(TYPE_ADB_KEYBOARD); 3023e80f690SMarkus Armbruster qdev_realize_and_unref(dev, adb_bus, &error_fatal); 3033e80f690SMarkus Armbruster dev = qdev_new(TYPE_ADB_MOUSE); 3043e80f690SMarkus Armbruster qdev_realize_and_unref(dev, adb_bus, &error_fatal); 30545fa67fbSAndreas Färber 3064bcbe0b6SEduardo Habkost if (machine_usb(machine)) { 307afb9a60eSGerd Hoffmann pci_create_simple(pci_bus, -1, "pci-ohci"); 3083cbee15bSj_mayer } 3093cbee15bSj_mayer 3103cbee15bSj_mayer if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) 3113cbee15bSj_mayer graphic_depth = 15; 3123cbee15bSj_mayer 3133cbee15bSj_mayer /* No PCI init: the BIOS will do it */ 3143cbee15bSj_mayer 3153e80f690SMarkus Armbruster dev = qdev_new(TYPE_FW_CFG_MEM); 31681a07050SMark Cave-Ayland fw_cfg = FW_CFG(dev); 31781a07050SMark Cave-Ayland qdev_prop_set_uint32(dev, "data_width", 1); 31881a07050SMark Cave-Ayland qdev_prop_set_bit(dev, "dma_enabled", false); 31981a07050SMark Cave-Ayland object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG, 320d2623129SMarkus Armbruster OBJECT(fw_cfg)); 32181a07050SMark Cave-Ayland s = SYS_BUS_DEVICE(dev); 3223c6ef471SMarkus Armbruster sysbus_realize_and_unref(s, &error_fatal); 32381a07050SMark Cave-Ayland sysbus_mmio_map(s, 0, CFG_ADDR); 32481a07050SMark Cave-Ayland sysbus_mmio_map(s, 1, CFG_ADDR + 2); 32581a07050SMark Cave-Ayland 3265836d168SIgor Mammedov fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)smp_cpus); 327fe6b6346SLike Xu fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)machine->smp.max_cpus); 328271dd5e0Sblueswir1 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); 329271dd5e0Sblueswir1 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW); 330513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base); 331513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); 332b8df3255SBALATON Zoltan if (machine->kernel_cmdline) { 333b9e17a34SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base); 334b8df3255SBALATON Zoltan pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, 335b8df3255SBALATON Zoltan machine->kernel_cmdline); 336513f789fSblueswir1 } else { 337513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0); 338513f789fSblueswir1 } 339513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base); 340513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); 341513f789fSblueswir1 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device); 3427f1aec5fSLaurent Vivier 3437f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width); 3447f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height); 3457f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth); 3467f1aec5fSLaurent Vivier 34745024f09SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled()); 348dc333cd6SAlexander Graf if (kvm_enabled()) { 34945024f09SAlexander Graf uint8_t *hypercall; 35045024f09SAlexander Graf 3517267c094SAnthony Liguori hypercall = g_malloc(16); 35245024f09SAlexander Graf kvmppc_get_hypercall(env, hypercall, 16); 35345024f09SAlexander Graf fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16); 35445024f09SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid()); 355dc333cd6SAlexander Graf } 356caae6c96SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, tbfreq); 357a1014f25SAlexander Graf /* Mac OS X requires a "known good" clock-frequency value; pass it one. */ 3589d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_CLOCKFREQ, CLOCKFREQ); 3599d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_BUSFREQ, BUSFREQ); 360dc333cd6SAlexander Graf 361b50de5cdSMark Cave-Ayland /* MacOS NDRV VGA driver */ 362b50de5cdSMark Cave-Ayland filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, NDRV_VGA_FILENAME); 363b50de5cdSMark Cave-Ayland if (filename) { 3649776874fSPeter Maydell gchar *ndrv_file; 3659776874fSPeter Maydell gsize ndrv_size; 366b50de5cdSMark Cave-Ayland 3679776874fSPeter Maydell if (g_file_get_contents(filename, &ndrv_file, &ndrv_size, NULL)) { 368b50de5cdSMark Cave-Ayland fw_cfg_add_file(fw_cfg, "ndrv/qemu_vga.ndrv", ndrv_file, ndrv_size); 369b50de5cdSMark Cave-Ayland } 370b50de5cdSMark Cave-Ayland g_free(filename); 371b50de5cdSMark Cave-Ayland } 372b50de5cdSMark Cave-Ayland 373513f789fSblueswir1 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); 3743cbee15bSj_mayer } 3753cbee15bSj_mayer 376bbcc635fSMark Cave-Ayland /* 377bbcc635fSMark Cave-Ayland * Implementation of an interface to adjust firmware path 378bbcc635fSMark Cave-Ayland * for the bootindex property handling. 379bbcc635fSMark Cave-Ayland */ 380bbcc635fSMark Cave-Ayland static char *heathrow_fw_dev_path(FWPathProvider *p, BusState *bus, 381bbcc635fSMark Cave-Ayland DeviceState *dev) 382bbcc635fSMark Cave-Ayland { 383bbcc635fSMark Cave-Ayland PCIDevice *pci; 384bbcc635fSMark Cave-Ayland MACIOIDEState *macio_ide; 385bbcc635fSMark Cave-Ayland 386bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "macio-oldworld")) { 387bbcc635fSMark Cave-Ayland pci = PCI_DEVICE(dev); 388bbcc635fSMark Cave-Ayland return g_strdup_printf("mac-io@%x", PCI_SLOT(pci->devfn)); 389bbcc635fSMark Cave-Ayland } 390bbcc635fSMark Cave-Ayland 391bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "macio-ide")) { 392bbcc635fSMark Cave-Ayland macio_ide = MACIO_IDE(dev); 393bbcc635fSMark Cave-Ayland return g_strdup_printf("ata-3@%x", macio_ide->addr); 394bbcc635fSMark Cave-Ayland } 395bbcc635fSMark Cave-Ayland 396bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-hd")) { 397484d366eSMark Cave-Ayland return g_strdup("disk"); 398bbcc635fSMark Cave-Ayland } 399bbcc635fSMark Cave-Ayland 400bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-cd")) { 401bbcc635fSMark Cave-Ayland return g_strdup("cdrom"); 402bbcc635fSMark Cave-Ayland } 403bbcc635fSMark Cave-Ayland 404bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "virtio-blk-device")) { 405bbcc635fSMark Cave-Ayland return g_strdup("disk"); 406bbcc635fSMark Cave-Ayland } 407bbcc635fSMark Cave-Ayland 408bbcc635fSMark Cave-Ayland return NULL; 409bbcc635fSMark Cave-Ayland } 410bbcc635fSMark Cave-Ayland 411dc0ca80eSEric Auger static int heathrow_kvm_type(MachineState *machine, const char *arg) 412277c7a4dSAlexander Graf { 413277c7a4dSAlexander Graf /* Always force PR KVM */ 414277c7a4dSAlexander Graf return 2; 415277c7a4dSAlexander Graf } 416277c7a4dSAlexander Graf 417c8bd3526SMark Cave-Ayland static void heathrow_class_init(ObjectClass *oc, void *data) 418e264d29dSEduardo Habkost { 419c8bd3526SMark Cave-Ayland MachineClass *mc = MACHINE_CLASS(oc); 420bbcc635fSMark Cave-Ayland FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc); 421c8bd3526SMark Cave-Ayland 422e264d29dSEduardo Habkost mc->desc = "Heathrow based PowerMAC"; 423e264d29dSEduardo Habkost mc->init = ppc_heathrow_init; 4242059839bSMarkus Armbruster mc->block_default_type = IF_IDE; 42583234b82SPeter Maydell /* SMP is not supported currently */ 42683234b82SPeter Maydell mc->max_cpus = 1; 42746214a27SAndreas Färber #ifndef TARGET_PPC64 428ea0ac7f6SPhilippe Mathieu-Daudé mc->is_default = true; 42946214a27SAndreas Färber #endif 430f309ae85SEduardo Habkost /* TOFIX "cad" when Mac floppy is implemented */ 431e264d29dSEduardo Habkost mc->default_boot_order = "cd"; 432e264d29dSEduardo Habkost mc->kvm_type = heathrow_kvm_type; 433f4c6604eSIgor Mammedov mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("750_v3.1"); 4343232794bSMark Cave-Ayland mc->default_display = "std"; 435bbcc635fSMark Cave-Ayland mc->ignore_boot_device_suffixes = true; 4368ee06e4cSIgor Mammedov mc->default_ram_id = "ppc_heathrow.ram"; 437bbcc635fSMark Cave-Ayland fwc->get_dev_path = heathrow_fw_dev_path; 438f80f9ec9SAnthony Liguori } 439f80f9ec9SAnthony Liguori 440c8bd3526SMark Cave-Ayland static const TypeInfo ppc_heathrow_machine_info = { 441c8bd3526SMark Cave-Ayland .name = MACHINE_TYPE_NAME("g3beige"), 442c8bd3526SMark Cave-Ayland .parent = TYPE_MACHINE, 443bbcc635fSMark Cave-Ayland .class_init = heathrow_class_init, 444bbcc635fSMark Cave-Ayland .interfaces = (InterfaceInfo[]) { 445bbcc635fSMark Cave-Ayland { TYPE_FW_PATH_PROVIDER }, 446bbcc635fSMark Cave-Ayland { } 447bbcc635fSMark Cave-Ayland }, 448c8bd3526SMark Cave-Ayland }; 449c8bd3526SMark Cave-Ayland 450c8bd3526SMark Cave-Ayland static void ppc_heathrow_register_types(void) 451c8bd3526SMark Cave-Ayland { 452c8bd3526SMark Cave-Ayland type_register_static(&ppc_heathrow_machine_info); 453c8bd3526SMark Cave-Ayland } 454c8bd3526SMark Cave-Ayland 455c8bd3526SMark Cave-Ayland type_init(ppc_heathrow_register_types); 456