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" 292c65db5eSPaolo Bonzini #include "qemu/datadir.h" 30ab3dd749SPhilippe Mathieu-Daudé #include "qemu/units.h" 31da34e65cSMarkus Armbruster #include "qapi/error.h" 320d09e41aSPaolo Bonzini #include "hw/ppc/ppc.h" 33a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h" 34baec1910SAndreas Färber #include "mac.h" 350d09e41aSPaolo Bonzini #include "hw/input/adb.h" 369c17d615SPaolo Bonzini #include "sysemu/sysemu.h" 371422e32dSPaolo Bonzini #include "net/net.h" 380d09e41aSPaolo Bonzini #include "hw/isa/isa.h" 39baec1910SAndreas Färber #include "hw/pci/pci.h" 40a773e64aSMark Cave-Ayland #include "hw/pci/pci_host.h" 41baec1910SAndreas Färber #include "hw/boards.h" 420d09e41aSPaolo Bonzini #include "hw/nvram/fw_cfg.h" 430d09e41aSPaolo Bonzini #include "hw/char/escc.h" 44e1218e48SMark Cave-Ayland #include "hw/misc/macio/macio.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 63464c73e8SBALATON Zoltan #define PROM_BASE 0xffc00000 64464c73e8SBALATON Zoltan #define PROM_SIZE (4 * MiB) 65a773e64aSMark Cave-Ayland 66ddcd5531SGonglei static void fw_cfg_boot_set(void *opaque, const char *boot_device, 67ddcd5531SGonglei Error **errp) 68513f789fSblueswir1 { 6948779e50SGabriel L. Somlo fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); 70513f789fSblueswir1 } 71513f789fSblueswir1 72409dbce5SAurelien Jarno static uint64_t translate_kernel_address(void *opaque, uint64_t addr) 73409dbce5SAurelien Jarno { 74409dbce5SAurelien Jarno return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR; 75409dbce5SAurelien Jarno } 76409dbce5SAurelien Jarno 771bba0dc9SAndreas Färber static void ppc_heathrow_reset(void *opaque) 781bba0dc9SAndreas Färber { 79cd79664fSAndreas Färber PowerPCCPU *cpu = opaque; 801bba0dc9SAndreas Färber 81cd79664fSAndreas Färber cpu_reset(CPU(cpu)); 821bba0dc9SAndreas Färber } 831bba0dc9SAndreas Färber 843ef96221SMarcel Apfelbaum static void ppc_heathrow_init(MachineState *machine) 853cbee15bSj_mayer { 863ef96221SMarcel Apfelbaum ram_addr_t ram_size = machine->ram_size; 87cd7b9498SPaolo Bonzini const char *bios_name = machine->firmware ?: PROM_FILENAME; 883ef96221SMarcel Apfelbaum const char *boot_device = machine->boot_order; 8972c33dd7SAndreas Färber PowerPCCPU *cpu = NULL; 90e2684c0bSAndreas Färber CPUPPCState *env = NULL; 915cea8590SPaul Brook char *filename; 92b8df3255SBALATON Zoltan int i; 93c92bb2c7SAvi Kivity MemoryRegion *bios = g_new(MemoryRegion, 1); 94b9e17a34SAlexander Graf uint32_t kernel_base, initrd_base, cmdline_base = 0; 957373048cSblueswir1 int32_t kernel_size, initrd_size; 963cbee15bSj_mayer PCIBus *pci_bus; 977d612261SMarkus Armbruster PCIDevice *macio; 9807a7484eSAndreas Färber MACIOIDEState *macio_ide; 99348b8d1aSMark Cave-Ayland ESCCState *escc; 100a773e64aSMark Cave-Ayland SysBusDevice *s; 101c2964600SMark Cave-Ayland DeviceState *dev, *pic_dev; 102293c867dSAndreas Färber BusState *adb_bus; 103464c73e8SBALATON Zoltan uint64_t bios_addr; 1049776874fSPeter Maydell int bios_size; 105fe6b6346SLike Xu unsigned int smp_cpus = machine->smp.cpus; 106513f789fSblueswir1 uint16_t ppc_boot_device; 107f455e98cSGerd Hoffmann DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; 108271dd5e0Sblueswir1 void *fw_cfg; 109caae6c96SAlexander Graf uint64_t tbfreq; 1103cbee15bSj_mayer 1113cbee15bSj_mayer /* init CPUs */ 1123cbee15bSj_mayer for (i = 0; i < smp_cpus; i++) { 113f4c6604eSIgor Mammedov cpu = POWERPC_CPU(cpu_create(machine->cpu_type)); 11472c33dd7SAndreas Färber env = &cpu->env; 11572c33dd7SAndreas Färber 116b0fb43d8Saurel32 /* Set time-base frequency to 16.6 Mhz */ 117536d8cdaSAlexander Graf cpu_ppc_tb_init(env, TBFREQ); 118cd79664fSAndreas Färber qemu_register_reset(ppc_heathrow_reset, cpu); 1193cbee15bSj_mayer } 1203cbee15bSj_mayer 1213cbee15bSj_mayer /* allocate RAM */ 122ab3dd749SPhilippe Mathieu-Daudé if (ram_size > 2047 * MiB) { 123ab3dd749SPhilippe Mathieu-Daudé error_report("Too much memory for this machine: %" PRId64 " MB, " 124ab3dd749SPhilippe Mathieu-Daudé "maximum 2047 MB", ram_size / MiB); 1256b4079f8Saurel32 exit(1); 1266b4079f8Saurel32 } 1276b4079f8Saurel32 128c3481ab0SBALATON Zoltan memory_region_add_subregion(get_system_memory(), 0, machine->ram); 129a748ab6dSaurel32 130464c73e8SBALATON Zoltan /* allocate and load firmware ROM */ 131464c73e8SBALATON Zoltan memory_region_init_rom(bios, NULL, "ppc_heathrow.bios", PROM_SIZE, 132f8ed85acSMarkus Armbruster &error_fatal); 133c3481ab0SBALATON Zoltan memory_region_add_subregion(get_system_memory(), PROM_BASE, bios); 134e206ad48SHu Tao 1355cea8590SPaul Brook filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); 1365cea8590SPaul Brook if (filename) { 137464c73e8SBALATON Zoltan /* Load OpenBIOS (ELF) */ 138464c73e8SBALATON Zoltan bios_size = load_elf(filename, NULL, NULL, NULL, NULL, &bios_addr, 139464c73e8SBALATON Zoltan NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0); 140464c73e8SBALATON Zoltan /* Unfortunately, load_elf sign-extends reading elf32 */ 141464c73e8SBALATON Zoltan bios_addr = (uint32_t)bios_addr; 142464c73e8SBALATON Zoltan 143464c73e8SBALATON Zoltan if (bios_size <= 0) { 144b8df3255SBALATON Zoltan /* or if could not load ELF try loading a binary ROM image */ 145464c73e8SBALATON Zoltan bios_size = load_image_targphys(filename, PROM_BASE, PROM_SIZE); 146464c73e8SBALATON Zoltan bios_addr = PROM_BASE; 147464c73e8SBALATON Zoltan } 1487267c094SAnthony Liguori g_free(filename); 1495cea8590SPaul Brook } else { 1505cea8590SPaul Brook bios_size = -1; 1515cea8590SPaul Brook } 152464c73e8SBALATON Zoltan if (bios_size < 0 || bios_addr - PROM_BASE + bios_size > PROM_SIZE) { 153c525436eSMarkus Armbruster error_report("could not load PowerPC bios '%s'", bios_name); 1543cbee15bSj_mayer exit(1); 1553cbee15bSj_mayer } 1563cbee15bSj_mayer 157b8df3255SBALATON Zoltan if (machine->kernel_filename) { 158ca20cf32SBlue Swirl int bswap_needed; 159ca20cf32SBlue Swirl 160ca20cf32SBlue Swirl #ifdef BSWAP_NEEDED 161ca20cf32SBlue Swirl bswap_needed = 1; 162ca20cf32SBlue Swirl #else 163ca20cf32SBlue Swirl bswap_needed = 0; 164ca20cf32SBlue Swirl #endif 1653cbee15bSj_mayer kernel_base = KERNEL_LOAD_ADDR; 166b8df3255SBALATON Zoltan kernel_size = load_elf(machine->kernel_filename, NULL, 167617160c9SBALATON Zoltan translate_kernel_address, NULL, NULL, NULL, 168617160c9SBALATON Zoltan NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0); 16952f163b7Sblueswir1 if (kernel_size < 0) 170b8df3255SBALATON Zoltan kernel_size = load_aout(machine->kernel_filename, kernel_base, 171ca20cf32SBlue Swirl ram_size - kernel_base, bswap_needed, 172ca20cf32SBlue Swirl TARGET_PAGE_SIZE); 17352f163b7Sblueswir1 if (kernel_size < 0) 174b8df3255SBALATON Zoltan kernel_size = load_image_targphys(machine->kernel_filename, 17552f163b7Sblueswir1 kernel_base, 17652f163b7Sblueswir1 ram_size - kernel_base); 1773cbee15bSj_mayer if (kernel_size < 0) { 178b8df3255SBALATON Zoltan error_report("could not load kernel '%s'", 179b8df3255SBALATON Zoltan machine->kernel_filename); 1803cbee15bSj_mayer exit(1); 1813cbee15bSj_mayer } 1823cbee15bSj_mayer /* load initrd */ 183b8df3255SBALATON Zoltan if (machine->initrd_filename) { 184b8df3255SBALATON Zoltan initrd_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + 185b8df3255SBALATON Zoltan KERNEL_GAP); 186b8df3255SBALATON Zoltan initrd_size = load_image_targphys(machine->initrd_filename, 187b8df3255SBALATON Zoltan initrd_base, 188dcac9679Spbrook ram_size - initrd_base); 1893cbee15bSj_mayer if (initrd_size < 0) { 190c525436eSMarkus Armbruster error_report("could not load initial ram disk '%s'", 191b8df3255SBALATON Zoltan machine->initrd_filename); 1923cbee15bSj_mayer exit(1); 1933cbee15bSj_mayer } 19439d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size); 1953cbee15bSj_mayer } else { 1963cbee15bSj_mayer initrd_base = 0; 1973cbee15bSj_mayer initrd_size = 0; 19839d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP); 1993cbee15bSj_mayer } 2006ac0e82dSbalrog ppc_boot_device = 'm'; 2013cbee15bSj_mayer } else { 2023cbee15bSj_mayer kernel_base = 0; 2033cbee15bSj_mayer kernel_size = 0; 2043cbee15bSj_mayer initrd_base = 0; 2053cbee15bSj_mayer initrd_size = 0; 20628c5af54Sj_mayer ppc_boot_device = '\0'; 2070d913fdbSj_mayer for (i = 0; boot_device[i] != '\0'; i++) { 20828c5af54Sj_mayer /* TOFIX: for now, the second IDE channel is not properly 2090d913fdbSj_mayer * used by OHW. The Mac floppy disk are not emulated. 21028c5af54Sj_mayer * For now, OHW cannot boot from the network. 21128c5af54Sj_mayer */ 21228c5af54Sj_mayer #if 0 2130d913fdbSj_mayer if (boot_device[i] >= 'a' && boot_device[i] <= 'f') { 2140d913fdbSj_mayer ppc_boot_device = boot_device[i]; 21528c5af54Sj_mayer break; 2160d913fdbSj_mayer } 21728c5af54Sj_mayer #else 2180d913fdbSj_mayer if (boot_device[i] >= 'c' && boot_device[i] <= 'd') { 2190d913fdbSj_mayer ppc_boot_device = boot_device[i]; 22028c5af54Sj_mayer break; 2210d913fdbSj_mayer } 22228c5af54Sj_mayer #endif 22328c5af54Sj_mayer } 22428c5af54Sj_mayer if (ppc_boot_device == '\0') { 2256f76b817SAlistair Francis error_report("No valid boot device for G3 Beige machine"); 22628c5af54Sj_mayer exit(1); 22728c5af54Sj_mayer } 2283cbee15bSj_mayer } 2293cbee15bSj_mayer 230*49ac51aeSMark Cave-Ayland /* Grackle PCI host bridge */ 231*49ac51aeSMark Cave-Ayland dev = qdev_new(TYPE_GRACKLE_PCI_HOST_BRIDGE); 232*49ac51aeSMark Cave-Ayland qdev_prop_set_uint32(dev, "ofw-addr", 0x80000000); 233*49ac51aeSMark Cave-Ayland s = SYS_BUS_DEVICE(dev); 234*49ac51aeSMark Cave-Ayland sysbus_realize_and_unref(s, &error_fatal); 235*49ac51aeSMark Cave-Ayland 236*49ac51aeSMark Cave-Ayland sysbus_mmio_map(s, 0, GRACKLE_BASE); 237*49ac51aeSMark Cave-Ayland sysbus_mmio_map(s, 1, GRACKLE_BASE + 0x200000); 238*49ac51aeSMark Cave-Ayland /* PCI hole */ 239*49ac51aeSMark Cave-Ayland memory_region_add_subregion(get_system_memory(), 0x80000000ULL, 240*49ac51aeSMark Cave-Ayland sysbus_mmio_get_region(s, 2)); 241*49ac51aeSMark Cave-Ayland /* Register 2 MB of ISA IO space */ 242*49ac51aeSMark Cave-Ayland memory_region_add_subregion(get_system_memory(), 0xfe000000, 243*49ac51aeSMark Cave-Ayland sysbus_mmio_get_region(s, 3)); 244*49ac51aeSMark Cave-Ayland 2453cbee15bSj_mayer /* XXX: we register only 1 output pin for heathrow PIC */ 2463e80f690SMarkus Armbruster pic_dev = qdev_new(TYPE_HEATHROW); 2473c6ef471SMarkus Armbruster sysbus_realize_and_unref(SYS_BUS_DEVICE(pic_dev), &error_fatal); 248a5ed75feSMark Cave-Ayland 2493cbee15bSj_mayer /* Connect the heathrow PIC outputs to the 6xx bus */ 2503cbee15bSj_mayer for (i = 0; i < smp_cpus; i++) { 2513cbee15bSj_mayer switch (PPC_INPUT(env)) { 2523cbee15bSj_mayer case PPC_FLAGS_INPUT_6xx: 253a5ed75feSMark Cave-Ayland qdev_connect_gpio_out(pic_dev, 0, 254a5ed75feSMark Cave-Ayland ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]); 2553cbee15bSj_mayer break; 2563cbee15bSj_mayer default: 257c525436eSMarkus Armbruster error_report("Bus model not supported on OldWorld Mac machine"); 258c525436eSMarkus Armbruster exit(1); 2593cbee15bSj_mayer } 2603cbee15bSj_mayer } 2613cbee15bSj_mayer 262caae6c96SAlexander Graf /* Timebase Frequency */ 263caae6c96SAlexander Graf if (kvm_enabled()) { 264caae6c96SAlexander Graf tbfreq = kvmppc_get_tbfreq(); 265caae6c96SAlexander Graf } else { 266caae6c96SAlexander Graf tbfreq = TBFREQ; 267caae6c96SAlexander Graf } 268caae6c96SAlexander Graf 269b950914dSMark Cave-Ayland for (i = 0; i < 4; i++) { 270b950914dSMark Cave-Ayland qdev_connect_gpio_out(dev, i, qdev_get_gpio_in(pic_dev, 0x15 + i)); 271b950914dSMark Cave-Ayland } 272b950914dSMark Cave-Ayland 273a773e64aSMark Cave-Ayland pci_bus = PCI_HOST_BRIDGE(dev)->bus; 274a773e64aSMark Cave-Ayland 2753e20ad3aSAurelien Jarno pci_vga_init(pci_bus); 2763cbee15bSj_mayer 277343bd85aSMark Cave-Ayland for (i = 0; i < nb_nics; i++) { 27829b358f9SDavid Gibson pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); 279343bd85aSMark Cave-Ayland } 280e4bcb14cSths 281d8f94e1bSJohn Snow ide_drive_get(hd, ARRAY_SIZE(hd)); 282bd4524edSaurel32 283343bd85aSMark Cave-Ayland /* MacIO */ 284bb997e5cSBALATON Zoltan macio = pci_new(PCI_DEVFN(16, 0), TYPE_OLDWORLD_MACIO); 28507a7484eSAndreas Färber dev = DEVICE(macio); 286b981289cSAlexander Graf qdev_prop_set_uint64(dev, "frequency", tbfreq); 2875325cc34SMarkus Armbruster object_property_set_link(OBJECT(macio), "pic", OBJECT(pic_dev), 288017812dfSMark Cave-Ayland &error_abort); 289348b8d1aSMark Cave-Ayland 290348b8d1aSMark Cave-Ayland escc = ESCC(object_resolve_path_component(OBJECT(macio), "escc")); 291348b8d1aSMark Cave-Ayland qdev_prop_set_chr(DEVICE(escc), "chrA", serial_hd(0)); 292348b8d1aSMark Cave-Ayland qdev_prop_set_chr(DEVICE(escc), "chrB", serial_hd(1)); 293348b8d1aSMark Cave-Ayland 2949307d06dSMarkus Armbruster pci_realize_and_unref(macio, pci_bus, &error_fatal); 29507a7484eSAndreas Färber 29607a7484eSAndreas Färber macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), 29714eefd0eSAlexander Graf "ide[0]")); 29807a7484eSAndreas Färber macio_ide_init_drives(macio_ide, hd); 29907a7484eSAndreas Färber 30014eefd0eSAlexander Graf macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio), 30114eefd0eSAlexander Graf "ide[1]")); 30214eefd0eSAlexander Graf macio_ide_init_drives(macio_ide, &hd[MAX_IDE_DEVS]); 3033cbee15bSj_mayer 304293c867dSAndreas Färber dev = DEVICE(object_resolve_path_component(OBJECT(macio), "cuda")); 305293c867dSAndreas Färber adb_bus = qdev_get_child_bus(dev, "adb.0"); 3063e80f690SMarkus Armbruster dev = qdev_new(TYPE_ADB_KEYBOARD); 3073e80f690SMarkus Armbruster qdev_realize_and_unref(dev, adb_bus, &error_fatal); 3083e80f690SMarkus Armbruster dev = qdev_new(TYPE_ADB_MOUSE); 3093e80f690SMarkus Armbruster qdev_realize_and_unref(dev, adb_bus, &error_fatal); 31045fa67fbSAndreas Färber 3114bcbe0b6SEduardo Habkost if (machine_usb(machine)) { 312afb9a60eSGerd Hoffmann pci_create_simple(pci_bus, -1, "pci-ohci"); 3133cbee15bSj_mayer } 3143cbee15bSj_mayer 3153cbee15bSj_mayer if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) 3163cbee15bSj_mayer graphic_depth = 15; 3173cbee15bSj_mayer 3183cbee15bSj_mayer /* No PCI init: the BIOS will do it */ 3193cbee15bSj_mayer 3203e80f690SMarkus Armbruster dev = qdev_new(TYPE_FW_CFG_MEM); 32181a07050SMark Cave-Ayland fw_cfg = FW_CFG(dev); 32281a07050SMark Cave-Ayland qdev_prop_set_uint32(dev, "data_width", 1); 32381a07050SMark Cave-Ayland qdev_prop_set_bit(dev, "dma_enabled", false); 32481a07050SMark Cave-Ayland object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG, 325d2623129SMarkus Armbruster OBJECT(fw_cfg)); 32681a07050SMark Cave-Ayland s = SYS_BUS_DEVICE(dev); 3273c6ef471SMarkus Armbruster sysbus_realize_and_unref(s, &error_fatal); 32881a07050SMark Cave-Ayland sysbus_mmio_map(s, 0, CFG_ADDR); 32981a07050SMark Cave-Ayland sysbus_mmio_map(s, 1, CFG_ADDR + 2); 33081a07050SMark Cave-Ayland 3315836d168SIgor Mammedov fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)smp_cpus); 332fe6b6346SLike Xu fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)machine->smp.max_cpus); 333271dd5e0Sblueswir1 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); 334271dd5e0Sblueswir1 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW); 335513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base); 336513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); 337b8df3255SBALATON Zoltan if (machine->kernel_cmdline) { 338b9e17a34SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base); 339b8df3255SBALATON Zoltan pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, 340b8df3255SBALATON Zoltan machine->kernel_cmdline); 341513f789fSblueswir1 } else { 342513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0); 343513f789fSblueswir1 } 344513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base); 345513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); 346513f789fSblueswir1 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device); 3477f1aec5fSLaurent Vivier 3487f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width); 3497f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height); 3507f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth); 3517f1aec5fSLaurent Vivier 35245024f09SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled()); 353dc333cd6SAlexander Graf if (kvm_enabled()) { 35445024f09SAlexander Graf uint8_t *hypercall; 35545024f09SAlexander Graf 3567267c094SAnthony Liguori hypercall = g_malloc(16); 35745024f09SAlexander Graf kvmppc_get_hypercall(env, hypercall, 16); 35845024f09SAlexander Graf fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16); 35945024f09SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid()); 360dc333cd6SAlexander Graf } 361caae6c96SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, tbfreq); 362a1014f25SAlexander Graf /* Mac OS X requires a "known good" clock-frequency value; pass it one. */ 3639d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_CLOCKFREQ, CLOCKFREQ); 3649d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_BUSFREQ, BUSFREQ); 365dc333cd6SAlexander Graf 366b50de5cdSMark Cave-Ayland /* MacOS NDRV VGA driver */ 367b50de5cdSMark Cave-Ayland filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, NDRV_VGA_FILENAME); 368b50de5cdSMark Cave-Ayland if (filename) { 3699776874fSPeter Maydell gchar *ndrv_file; 3709776874fSPeter Maydell gsize ndrv_size; 371b50de5cdSMark Cave-Ayland 3729776874fSPeter Maydell if (g_file_get_contents(filename, &ndrv_file, &ndrv_size, NULL)) { 373b50de5cdSMark Cave-Ayland fw_cfg_add_file(fw_cfg, "ndrv/qemu_vga.ndrv", ndrv_file, ndrv_size); 374b50de5cdSMark Cave-Ayland } 375b50de5cdSMark Cave-Ayland g_free(filename); 376b50de5cdSMark Cave-Ayland } 377b50de5cdSMark Cave-Ayland 378513f789fSblueswir1 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); 3793cbee15bSj_mayer } 3803cbee15bSj_mayer 381bbcc635fSMark Cave-Ayland /* 382bbcc635fSMark Cave-Ayland * Implementation of an interface to adjust firmware path 383bbcc635fSMark Cave-Ayland * for the bootindex property handling. 384bbcc635fSMark Cave-Ayland */ 385bbcc635fSMark Cave-Ayland static char *heathrow_fw_dev_path(FWPathProvider *p, BusState *bus, 386bbcc635fSMark Cave-Ayland DeviceState *dev) 387bbcc635fSMark Cave-Ayland { 388bbcc635fSMark Cave-Ayland PCIDevice *pci; 389bbcc635fSMark Cave-Ayland IDEBus *ide_bus; 390bbcc635fSMark Cave-Ayland IDEState *ide_s; 391bbcc635fSMark Cave-Ayland MACIOIDEState *macio_ide; 392bbcc635fSMark Cave-Ayland 393bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "macio-oldworld")) { 394bbcc635fSMark Cave-Ayland pci = PCI_DEVICE(dev); 395bbcc635fSMark Cave-Ayland return g_strdup_printf("mac-io@%x", PCI_SLOT(pci->devfn)); 396bbcc635fSMark Cave-Ayland } 397bbcc635fSMark Cave-Ayland 398bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "macio-ide")) { 399bbcc635fSMark Cave-Ayland macio_ide = MACIO_IDE(dev); 400bbcc635fSMark Cave-Ayland return g_strdup_printf("ata-3@%x", macio_ide->addr); 401bbcc635fSMark Cave-Ayland } 402bbcc635fSMark Cave-Ayland 403bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-drive")) { 404bbcc635fSMark Cave-Ayland ide_bus = IDE_BUS(qdev_get_parent_bus(dev)); 405bbcc635fSMark Cave-Ayland ide_s = idebus_active_if(ide_bus); 406bbcc635fSMark Cave-Ayland 407bbcc635fSMark Cave-Ayland if (ide_s->drive_kind == IDE_CD) { 408bbcc635fSMark Cave-Ayland return g_strdup("cdrom"); 409bbcc635fSMark Cave-Ayland } 410bbcc635fSMark Cave-Ayland 411484d366eSMark Cave-Ayland return g_strdup("disk"); 412bbcc635fSMark Cave-Ayland } 413bbcc635fSMark Cave-Ayland 414bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-hd")) { 415484d366eSMark Cave-Ayland return g_strdup("disk"); 416bbcc635fSMark Cave-Ayland } 417bbcc635fSMark Cave-Ayland 418bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-cd")) { 419bbcc635fSMark Cave-Ayland return g_strdup("cdrom"); 420bbcc635fSMark Cave-Ayland } 421bbcc635fSMark Cave-Ayland 422bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "virtio-blk-device")) { 423bbcc635fSMark Cave-Ayland return g_strdup("disk"); 424bbcc635fSMark Cave-Ayland } 425bbcc635fSMark Cave-Ayland 426bbcc635fSMark Cave-Ayland return NULL; 427bbcc635fSMark Cave-Ayland } 428bbcc635fSMark Cave-Ayland 429dc0ca80eSEric Auger static int heathrow_kvm_type(MachineState *machine, const char *arg) 430277c7a4dSAlexander Graf { 431277c7a4dSAlexander Graf /* Always force PR KVM */ 432277c7a4dSAlexander Graf return 2; 433277c7a4dSAlexander Graf } 434277c7a4dSAlexander Graf 435c8bd3526SMark Cave-Ayland static void heathrow_class_init(ObjectClass *oc, void *data) 436e264d29dSEduardo Habkost { 437c8bd3526SMark Cave-Ayland MachineClass *mc = MACHINE_CLASS(oc); 438bbcc635fSMark Cave-Ayland FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc); 439c8bd3526SMark Cave-Ayland 440e264d29dSEduardo Habkost mc->desc = "Heathrow based PowerMAC"; 441e264d29dSEduardo Habkost mc->init = ppc_heathrow_init; 4422059839bSMarkus Armbruster mc->block_default_type = IF_IDE; 443e264d29dSEduardo Habkost mc->max_cpus = MAX_CPUS; 44446214a27SAndreas Färber #ifndef TARGET_PPC64 445ea0ac7f6SPhilippe Mathieu-Daudé mc->is_default = true; 44646214a27SAndreas Färber #endif 447f309ae85SEduardo Habkost /* TOFIX "cad" when Mac floppy is implemented */ 448e264d29dSEduardo Habkost mc->default_boot_order = "cd"; 449e264d29dSEduardo Habkost mc->kvm_type = heathrow_kvm_type; 450f4c6604eSIgor Mammedov mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("750_v3.1"); 4513232794bSMark Cave-Ayland mc->default_display = "std"; 452bbcc635fSMark Cave-Ayland mc->ignore_boot_device_suffixes = true; 4538ee06e4cSIgor Mammedov mc->default_ram_id = "ppc_heathrow.ram"; 454bbcc635fSMark Cave-Ayland fwc->get_dev_path = heathrow_fw_dev_path; 455f80f9ec9SAnthony Liguori } 456f80f9ec9SAnthony Liguori 457c8bd3526SMark Cave-Ayland static const TypeInfo ppc_heathrow_machine_info = { 458c8bd3526SMark Cave-Ayland .name = MACHINE_TYPE_NAME("g3beige"), 459c8bd3526SMark Cave-Ayland .parent = TYPE_MACHINE, 460bbcc635fSMark Cave-Ayland .class_init = heathrow_class_init, 461bbcc635fSMark Cave-Ayland .interfaces = (InterfaceInfo[]) { 462bbcc635fSMark Cave-Ayland { TYPE_FW_PATH_PROVIDER }, 463bbcc635fSMark Cave-Ayland { } 464bbcc635fSMark Cave-Ayland }, 465c8bd3526SMark Cave-Ayland }; 466c8bd3526SMark Cave-Ayland 467c8bd3526SMark Cave-Ayland static void ppc_heathrow_register_types(void) 468c8bd3526SMark Cave-Ayland { 469c8bd3526SMark Cave-Ayland type_register_static(&ppc_heathrow_machine_info); 470c8bd3526SMark Cave-Ayland } 471c8bd3526SMark Cave-Ayland 472c8bd3526SMark Cave-Ayland type_init(ppc_heathrow_register_types); 473