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 { 83cd7b9498SPaolo Bonzini const char *bios_name = machine->firmware ?: PROM_FILENAME; 8472c33dd7SAndreas Färber PowerPCCPU *cpu = NULL; 85e2684c0bSAndreas Färber CPUPPCState *env = NULL; 865cea8590SPaul Brook char *filename; 87*6120dc8dSBALATON Zoltan int i, bios_size = -1; 88c92bb2c7SAvi Kivity MemoryRegion *bios = g_new(MemoryRegion, 1); 8994c92e1aSBALATON Zoltan uint64_t bios_addr; 90*6120dc8dSBALATON Zoltan uint32_t kernel_base = 0, initrd_base = 0, cmdline_base = 0; 91*6120dc8dSBALATON Zoltan int32_t kernel_size = 0, initrd_size = 0; 923cbee15bSj_mayer PCIBus *pci_bus; 937d612261SMarkus Armbruster PCIDevice *macio; 9407a7484eSAndreas Färber MACIOIDEState *macio_ide; 95348b8d1aSMark Cave-Ayland ESCCState *escc; 96a773e64aSMark Cave-Ayland SysBusDevice *s; 97370022ceSMark Cave-Ayland DeviceState *dev, *pic_dev, *grackle_dev; 98293c867dSAndreas Färber BusState *adb_bus; 99513f789fSblueswir1 uint16_t ppc_boot_device; 100f455e98cSGerd Hoffmann DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 101271dd5e0Sblueswir1 void *fw_cfg; 1026b924abeSBALATON Zoltan uint64_t tbfreq = kvm_enabled() ? kvmppc_get_tbfreq() : TBFREQ; 1033cbee15bSj_mayer 1043cbee15bSj_mayer /* init CPUs */ 10594c92e1aSBALATON Zoltan for (i = 0; i < machine->smp.cpus; i++) { 106f4c6604eSIgor Mammedov cpu = POWERPC_CPU(cpu_create(machine->cpu_type)); 10772c33dd7SAndreas Färber env = &cpu->env; 10872c33dd7SAndreas Färber 109b0fb43d8Saurel32 /* Set time-base frequency to 16.6 Mhz */ 110536d8cdaSAlexander Graf cpu_ppc_tb_init(env, TBFREQ); 111cd79664fSAndreas Färber qemu_register_reset(ppc_heathrow_reset, cpu); 1123cbee15bSj_mayer } 1133cbee15bSj_mayer 1143cbee15bSj_mayer /* allocate RAM */ 11594c92e1aSBALATON Zoltan if (machine->ram_size > 2047 * MiB) { 116ab3dd749SPhilippe Mathieu-Daudé error_report("Too much memory for this machine: %" PRId64 " MB, " 11794c92e1aSBALATON Zoltan "maximum 2047 MB", machine->ram_size / MiB); 1186b4079f8Saurel32 exit(1); 1196b4079f8Saurel32 } 1206b4079f8Saurel32 121c3481ab0SBALATON Zoltan memory_region_add_subregion(get_system_memory(), 0, machine->ram); 122a748ab6dSaurel32 123464c73e8SBALATON Zoltan /* allocate and load firmware ROM */ 124464c73e8SBALATON Zoltan memory_region_init_rom(bios, NULL, "ppc_heathrow.bios", PROM_SIZE, 125f8ed85acSMarkus Armbruster &error_fatal); 126c3481ab0SBALATON Zoltan memory_region_add_subregion(get_system_memory(), PROM_BASE, bios); 127e206ad48SHu Tao 1285cea8590SPaul Brook filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); 1295cea8590SPaul Brook if (filename) { 130464c73e8SBALATON Zoltan /* Load OpenBIOS (ELF) */ 131464c73e8SBALATON Zoltan bios_size = load_elf(filename, NULL, NULL, NULL, NULL, &bios_addr, 132464c73e8SBALATON Zoltan NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0); 133464c73e8SBALATON Zoltan /* Unfortunately, load_elf sign-extends reading elf32 */ 134464c73e8SBALATON Zoltan bios_addr = (uint32_t)bios_addr; 135464c73e8SBALATON Zoltan 136464c73e8SBALATON Zoltan if (bios_size <= 0) { 137b8df3255SBALATON Zoltan /* or if could not load ELF try loading a binary ROM image */ 138464c73e8SBALATON Zoltan bios_size = load_image_targphys(filename, PROM_BASE, PROM_SIZE); 139464c73e8SBALATON Zoltan bios_addr = PROM_BASE; 140464c73e8SBALATON Zoltan } 1417267c094SAnthony Liguori g_free(filename); 1425cea8590SPaul Brook } 143464c73e8SBALATON Zoltan if (bios_size < 0 || bios_addr - PROM_BASE + bios_size > PROM_SIZE) { 144c525436eSMarkus Armbruster error_report("could not load PowerPC bios '%s'", bios_name); 1453cbee15bSj_mayer exit(1); 1463cbee15bSj_mayer } 1473cbee15bSj_mayer 148b8df3255SBALATON Zoltan if (machine->kernel_filename) { 149*6120dc8dSBALATON Zoltan int bswap_needed = 0; 150ca20cf32SBlue Swirl 151ca20cf32SBlue Swirl #ifdef BSWAP_NEEDED 152ca20cf32SBlue Swirl bswap_needed = 1; 153ca20cf32SBlue Swirl #endif 1543cbee15bSj_mayer kernel_base = KERNEL_LOAD_ADDR; 155b8df3255SBALATON Zoltan kernel_size = load_elf(machine->kernel_filename, NULL, 156617160c9SBALATON Zoltan translate_kernel_address, NULL, NULL, NULL, 157617160c9SBALATON Zoltan NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0); 15852f163b7Sblueswir1 if (kernel_size < 0) 159b8df3255SBALATON Zoltan kernel_size = load_aout(machine->kernel_filename, kernel_base, 16094c92e1aSBALATON Zoltan machine->ram_size - kernel_base, 16194c92e1aSBALATON Zoltan bswap_needed, TARGET_PAGE_SIZE); 16252f163b7Sblueswir1 if (kernel_size < 0) 163b8df3255SBALATON Zoltan kernel_size = load_image_targphys(machine->kernel_filename, 16452f163b7Sblueswir1 kernel_base, 16594c92e1aSBALATON Zoltan machine->ram_size - kernel_base); 1663cbee15bSj_mayer if (kernel_size < 0) { 167b8df3255SBALATON Zoltan error_report("could not load kernel '%s'", 168b8df3255SBALATON Zoltan machine->kernel_filename); 1693cbee15bSj_mayer exit(1); 1703cbee15bSj_mayer } 1713cbee15bSj_mayer /* load initrd */ 172b8df3255SBALATON Zoltan if (machine->initrd_filename) { 173b8df3255SBALATON Zoltan initrd_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + 174b8df3255SBALATON Zoltan KERNEL_GAP); 175b8df3255SBALATON Zoltan initrd_size = load_image_targphys(machine->initrd_filename, 176b8df3255SBALATON Zoltan initrd_base, 17794c92e1aSBALATON Zoltan machine->ram_size - initrd_base); 1783cbee15bSj_mayer if (initrd_size < 0) { 179c525436eSMarkus Armbruster error_report("could not load initial ram disk '%s'", 180b8df3255SBALATON Zoltan machine->initrd_filename); 1813cbee15bSj_mayer exit(1); 1823cbee15bSj_mayer } 18339d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size); 1843cbee15bSj_mayer } else { 18539d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP); 1863cbee15bSj_mayer } 1876ac0e82dSbalrog ppc_boot_device = 'm'; 1883cbee15bSj_mayer } else { 18928c5af54Sj_mayer ppc_boot_device = '\0'; 19094c92e1aSBALATON Zoltan for (i = 0; machine->boot_config.order[i] != '\0'; i++) { 19194c92e1aSBALATON Zoltan /* 19294c92e1aSBALATON Zoltan * TOFIX: for now, the second IDE channel is not properly 1930d913fdbSj_mayer * used by OHW. The Mac floppy disk are not emulated. 19428c5af54Sj_mayer * For now, OHW cannot boot from the network. 19528c5af54Sj_mayer */ 19628c5af54Sj_mayer #if 0 19794c92e1aSBALATON Zoltan if (machine->boot_config.order[i] >= 'a' && 19894c92e1aSBALATON Zoltan machine->boot_config.order[i] <= 'f') { 19994c92e1aSBALATON Zoltan ppc_boot_device = machine->boot_config.order[i]; 20028c5af54Sj_mayer break; 2010d913fdbSj_mayer } 20228c5af54Sj_mayer #else 20394c92e1aSBALATON Zoltan if (machine->boot_config.order[i] >= 'c' && 20494c92e1aSBALATON Zoltan machine->boot_config.order[i] <= 'd') { 20594c92e1aSBALATON Zoltan ppc_boot_device = machine->boot_config.order[i]; 20628c5af54Sj_mayer break; 2070d913fdbSj_mayer } 20828c5af54Sj_mayer #endif 20928c5af54Sj_mayer } 21028c5af54Sj_mayer if (ppc_boot_device == '\0') { 2116f76b817SAlistair Francis error_report("No valid boot device for G3 Beige machine"); 21228c5af54Sj_mayer exit(1); 21328c5af54Sj_mayer } 2143cbee15bSj_mayer } 2153cbee15bSj_mayer 21649ac51aeSMark Cave-Ayland /* Grackle PCI host bridge */ 217370022ceSMark Cave-Ayland grackle_dev = qdev_new(TYPE_GRACKLE_PCI_HOST_BRIDGE); 218370022ceSMark Cave-Ayland qdev_prop_set_uint32(grackle_dev, "ofw-addr", 0x80000000); 219370022ceSMark Cave-Ayland s = SYS_BUS_DEVICE(grackle_dev); 22049ac51aeSMark Cave-Ayland sysbus_realize_and_unref(s, &error_fatal); 22149ac51aeSMark Cave-Ayland 22249ac51aeSMark Cave-Ayland sysbus_mmio_map(s, 0, GRACKLE_BASE); 22349ac51aeSMark Cave-Ayland sysbus_mmio_map(s, 1, GRACKLE_BASE + 0x200000); 22449ac51aeSMark Cave-Ayland /* PCI hole */ 22549ac51aeSMark Cave-Ayland memory_region_add_subregion(get_system_memory(), 0x80000000ULL, 22649ac51aeSMark Cave-Ayland sysbus_mmio_get_region(s, 2)); 22749ac51aeSMark Cave-Ayland /* Register 2 MB of ISA IO space */ 22849ac51aeSMark Cave-Ayland memory_region_add_subregion(get_system_memory(), 0xfe000000, 22949ac51aeSMark Cave-Ayland sysbus_mmio_get_region(s, 3)); 23049ac51aeSMark Cave-Ayland 231370022ceSMark Cave-Ayland pci_bus = PCI_HOST_BRIDGE(grackle_dev)->bus; 232370022ceSMark Cave-Ayland 233370022ceSMark Cave-Ayland /* MacIO */ 234370022ceSMark Cave-Ayland macio = pci_new(PCI_DEVFN(16, 0), TYPE_OLDWORLD_MACIO); 235370022ceSMark Cave-Ayland dev = DEVICE(macio); 236370022ceSMark Cave-Ayland qdev_prop_set_uint64(dev, "frequency", tbfreq); 237370022ceSMark Cave-Ayland 238370022ceSMark Cave-Ayland escc = ESCC(object_resolve_path_component(OBJECT(macio), "escc")); 239370022ceSMark Cave-Ayland qdev_prop_set_chr(DEVICE(escc), "chrA", serial_hd(0)); 240370022ceSMark Cave-Ayland qdev_prop_set_chr(DEVICE(escc), "chrB", serial_hd(1)); 241370022ceSMark Cave-Ayland 242370022ceSMark Cave-Ayland pci_realize_and_unref(macio, pci_bus, &error_fatal); 243370022ceSMark Cave-Ayland 244370022ceSMark Cave-Ayland pic_dev = DEVICE(object_resolve_path_component(OBJECT(macio), "pic")); 245370022ceSMark Cave-Ayland for (i = 0; i < 4; i++) { 246370022ceSMark Cave-Ayland qdev_connect_gpio_out(grackle_dev, i, 247370022ceSMark Cave-Ayland qdev_get_gpio_in(pic_dev, 0x15 + i)); 248370022ceSMark Cave-Ayland } 249a5ed75feSMark Cave-Ayland 2503cbee15bSj_mayer /* Connect the heathrow PIC outputs to the 6xx bus */ 25194c92e1aSBALATON Zoltan for (i = 0; i < machine->smp.cpus; i++) { 2523cbee15bSj_mayer switch (PPC_INPUT(env)) { 2533cbee15bSj_mayer case PPC_FLAGS_INPUT_6xx: 254370022ceSMark Cave-Ayland /* XXX: we register only 1 output pin for heathrow PIC */ 255a5ed75feSMark Cave-Ayland qdev_connect_gpio_out(pic_dev, 0, 2560f3e0c6fSCédric Le Goater qdev_get_gpio_in(DEVICE(cpu), PPC6xx_INPUT_INT)); 2573cbee15bSj_mayer break; 2583cbee15bSj_mayer default: 259c525436eSMarkus Armbruster error_report("Bus model not supported on OldWorld Mac machine"); 260c525436eSMarkus Armbruster exit(1); 2613cbee15bSj_mayer } 2623cbee15bSj_mayer } 2633cbee15bSj_mayer 2643e20ad3aSAurelien Jarno pci_vga_init(pci_bus); 2653cbee15bSj_mayer 266343bd85aSMark Cave-Ayland for (i = 0; i < nb_nics; i++) { 26729b358f9SDavid Gibson pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); 268343bd85aSMark Cave-Ayland } 269e4bcb14cSths 270370022ceSMark Cave-Ayland /* MacIO IDE */ 271d8f94e1bSJohn Snow ide_drive_get(hd, ARRAY_SIZE(hd)); 27207a7484eSAndreas Färber macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), 27314eefd0eSAlexander Graf "ide[0]")); 27407a7484eSAndreas Färber macio_ide_init_drives(macio_ide, hd); 27507a7484eSAndreas Färber 27614eefd0eSAlexander Graf macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), 27714eefd0eSAlexander Graf "ide[1]")); 27814eefd0eSAlexander Graf macio_ide_init_drives(macio_ide, &hd[MAX_IDE_DEVS]); 2793cbee15bSj_mayer 280370022ceSMark Cave-Ayland /* MacIO CUDA/ADB */ 281293c867dSAndreas Färber dev = DEVICE(object_resolve_path_component(OBJECT(macio), "cuda")); 282293c867dSAndreas Färber adb_bus = qdev_get_child_bus(dev, "adb.0"); 2833e80f690SMarkus Armbruster dev = qdev_new(TYPE_ADB_KEYBOARD); 2843e80f690SMarkus Armbruster qdev_realize_and_unref(dev, adb_bus, &error_fatal); 2853e80f690SMarkus Armbruster dev = qdev_new(TYPE_ADB_MOUSE); 2863e80f690SMarkus Armbruster qdev_realize_and_unref(dev, adb_bus, &error_fatal); 28745fa67fbSAndreas Färber 2884bcbe0b6SEduardo Habkost if (machine_usb(machine)) { 289afb9a60eSGerd Hoffmann pci_create_simple(pci_bus, -1, "pci-ohci"); 2903cbee15bSj_mayer } 2913cbee15bSj_mayer 2923cbee15bSj_mayer if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) 2933cbee15bSj_mayer graphic_depth = 15; 2943cbee15bSj_mayer 2953cbee15bSj_mayer /* No PCI init: the BIOS will do it */ 2963cbee15bSj_mayer 2973e80f690SMarkus Armbruster dev = qdev_new(TYPE_FW_CFG_MEM); 29881a07050SMark Cave-Ayland fw_cfg = FW_CFG(dev); 29981a07050SMark Cave-Ayland qdev_prop_set_uint32(dev, "data_width", 1); 30081a07050SMark Cave-Ayland qdev_prop_set_bit(dev, "dma_enabled", false); 30181a07050SMark Cave-Ayland object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG, 302d2623129SMarkus Armbruster OBJECT(fw_cfg)); 30381a07050SMark Cave-Ayland s = SYS_BUS_DEVICE(dev); 3043c6ef471SMarkus Armbruster sysbus_realize_and_unref(s, &error_fatal); 30581a07050SMark Cave-Ayland sysbus_mmio_map(s, 0, CFG_ADDR); 30681a07050SMark Cave-Ayland sysbus_mmio_map(s, 1, CFG_ADDR + 2); 30781a07050SMark Cave-Ayland 30894c92e1aSBALATON Zoltan fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)machine->smp.cpus); 309fe6b6346SLike Xu fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)machine->smp.max_cpus); 31094c92e1aSBALATON Zoltan fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)machine->ram_size); 311271dd5e0Sblueswir1 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW); 312513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base); 313513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); 314b8df3255SBALATON Zoltan if (machine->kernel_cmdline) { 315b9e17a34SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base); 316b8df3255SBALATON Zoltan pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, 317b8df3255SBALATON Zoltan machine->kernel_cmdline); 318513f789fSblueswir1 } else { 319513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0); 320513f789fSblueswir1 } 321513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base); 322513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); 323513f789fSblueswir1 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device); 3247f1aec5fSLaurent Vivier 3257f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width); 3267f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height); 3277f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth); 3287f1aec5fSLaurent Vivier 32945024f09SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled()); 330dc333cd6SAlexander Graf if (kvm_enabled()) { 33145024f09SAlexander Graf uint8_t *hypercall; 33245024f09SAlexander Graf 3337267c094SAnthony Liguori hypercall = g_malloc(16); 33445024f09SAlexander Graf kvmppc_get_hypercall(env, hypercall, 16); 33545024f09SAlexander Graf fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16); 33645024f09SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid()); 337dc333cd6SAlexander Graf } 338caae6c96SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, tbfreq); 339a1014f25SAlexander Graf /* Mac OS X requires a "known good" clock-frequency value; pass it one. */ 3409d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_CLOCKFREQ, CLOCKFREQ); 3419d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_BUSFREQ, BUSFREQ); 342dc333cd6SAlexander Graf 343b50de5cdSMark Cave-Ayland /* MacOS NDRV VGA driver */ 344b50de5cdSMark Cave-Ayland filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, NDRV_VGA_FILENAME); 345b50de5cdSMark Cave-Ayland if (filename) { 3469776874fSPeter Maydell gchar *ndrv_file; 3479776874fSPeter Maydell gsize ndrv_size; 348b50de5cdSMark Cave-Ayland 3499776874fSPeter Maydell if (g_file_get_contents(filename, &ndrv_file, &ndrv_size, NULL)) { 350b50de5cdSMark Cave-Ayland fw_cfg_add_file(fw_cfg, "ndrv/qemu_vga.ndrv", ndrv_file, ndrv_size); 351b50de5cdSMark Cave-Ayland } 352b50de5cdSMark Cave-Ayland g_free(filename); 353b50de5cdSMark Cave-Ayland } 354b50de5cdSMark Cave-Ayland 355513f789fSblueswir1 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); 3563cbee15bSj_mayer } 3573cbee15bSj_mayer 358bbcc635fSMark Cave-Ayland /* 359bbcc635fSMark Cave-Ayland * Implementation of an interface to adjust firmware path 360bbcc635fSMark Cave-Ayland * for the bootindex property handling. 361bbcc635fSMark Cave-Ayland */ 362bbcc635fSMark Cave-Ayland static char *heathrow_fw_dev_path(FWPathProvider *p, BusState *bus, 363bbcc635fSMark Cave-Ayland DeviceState *dev) 364bbcc635fSMark Cave-Ayland { 365bbcc635fSMark Cave-Ayland PCIDevice *pci; 366bbcc635fSMark Cave-Ayland MACIOIDEState *macio_ide; 367bbcc635fSMark Cave-Ayland 368bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "macio-oldworld")) { 369bbcc635fSMark Cave-Ayland pci = PCI_DEVICE(dev); 370bbcc635fSMark Cave-Ayland return g_strdup_printf("mac-io@%x", PCI_SLOT(pci->devfn)); 371bbcc635fSMark Cave-Ayland } 372bbcc635fSMark Cave-Ayland 373bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "macio-ide")) { 374bbcc635fSMark Cave-Ayland macio_ide = MACIO_IDE(dev); 375bbcc635fSMark Cave-Ayland return g_strdup_printf("ata-3@%x", macio_ide->addr); 376bbcc635fSMark Cave-Ayland } 377bbcc635fSMark Cave-Ayland 378bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-hd")) { 379484d366eSMark Cave-Ayland return g_strdup("disk"); 380bbcc635fSMark Cave-Ayland } 381bbcc635fSMark Cave-Ayland 382bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-cd")) { 383bbcc635fSMark Cave-Ayland return g_strdup("cdrom"); 384bbcc635fSMark Cave-Ayland } 385bbcc635fSMark Cave-Ayland 386bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "virtio-blk-device")) { 387bbcc635fSMark Cave-Ayland return g_strdup("disk"); 388bbcc635fSMark Cave-Ayland } 389bbcc635fSMark Cave-Ayland 390bbcc635fSMark Cave-Ayland return NULL; 391bbcc635fSMark Cave-Ayland } 392bbcc635fSMark Cave-Ayland 393dc0ca80eSEric Auger static int heathrow_kvm_type(MachineState *machine, const char *arg) 394277c7a4dSAlexander Graf { 395277c7a4dSAlexander Graf /* Always force PR KVM */ 396277c7a4dSAlexander Graf return 2; 397277c7a4dSAlexander Graf } 398277c7a4dSAlexander Graf 399c8bd3526SMark Cave-Ayland static void heathrow_class_init(ObjectClass *oc, void *data) 400e264d29dSEduardo Habkost { 401c8bd3526SMark Cave-Ayland MachineClass *mc = MACHINE_CLASS(oc); 402bbcc635fSMark Cave-Ayland FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc); 403c8bd3526SMark Cave-Ayland 404e264d29dSEduardo Habkost mc->desc = "Heathrow based PowerMAC"; 405e264d29dSEduardo Habkost mc->init = ppc_heathrow_init; 4062059839bSMarkus Armbruster mc->block_default_type = IF_IDE; 40783234b82SPeter Maydell /* SMP is not supported currently */ 40883234b82SPeter Maydell mc->max_cpus = 1; 40946214a27SAndreas Färber #ifndef TARGET_PPC64 410ea0ac7f6SPhilippe Mathieu-Daudé mc->is_default = true; 41146214a27SAndreas Färber #endif 412f309ae85SEduardo Habkost /* TOFIX "cad" when Mac floppy is implemented */ 413e264d29dSEduardo Habkost mc->default_boot_order = "cd"; 414e264d29dSEduardo Habkost mc->kvm_type = heathrow_kvm_type; 415f4c6604eSIgor Mammedov mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("750_v3.1"); 4163232794bSMark Cave-Ayland mc->default_display = "std"; 417bbcc635fSMark Cave-Ayland mc->ignore_boot_device_suffixes = true; 4188ee06e4cSIgor Mammedov mc->default_ram_id = "ppc_heathrow.ram"; 419bbcc635fSMark Cave-Ayland fwc->get_dev_path = heathrow_fw_dev_path; 420f80f9ec9SAnthony Liguori } 421f80f9ec9SAnthony Liguori 422c8bd3526SMark Cave-Ayland static const TypeInfo ppc_heathrow_machine_info = { 423c8bd3526SMark Cave-Ayland .name = MACHINE_TYPE_NAME("g3beige"), 424c8bd3526SMark Cave-Ayland .parent = TYPE_MACHINE, 425bbcc635fSMark Cave-Ayland .class_init = heathrow_class_init, 426bbcc635fSMark Cave-Ayland .interfaces = (InterfaceInfo[]) { 427bbcc635fSMark Cave-Ayland { TYPE_FW_PATH_PROVIDER }, 428bbcc635fSMark Cave-Ayland { } 429bbcc635fSMark Cave-Ayland }, 430c8bd3526SMark Cave-Ayland }; 431c8bd3526SMark Cave-Ayland 432c8bd3526SMark Cave-Ayland static void ppc_heathrow_register_types(void) 433c8bd3526SMark Cave-Ayland { 434c8bd3526SMark Cave-Ayland type_register_static(&ppc_heathrow_machine_info); 435c8bd3526SMark Cave-Ayland } 436c8bd3526SMark Cave-Ayland 437c8bd3526SMark Cave-Ayland type_init(ppc_heathrow_register_types); 438