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"
319c2ff9cdSPierrick Bouvier #include "exec/target_page.h"
320d09e41aSPaolo Bonzini #include "hw/ppc/ppc.h"
33a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
34cfb47bfaSBALATON Zoltan #include "hw/boards.h"
350d09e41aSPaolo Bonzini #include "hw/input/adb.h"
3632cad1ffSPhilippe Mathieu-Daudé #include "system/system.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"
4187e5a4f8SBALATON Zoltan #include "hw/pci-host/grackle.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"
4932cad1ffSPhilippe Mathieu-Daudé #include "system/kvm.h"
5032cad1ffSPhilippe Mathieu-Daudé #include "system/reset.h"
51dc333cd6SAlexander Graf #include "kvm_ppc.h"
523cbee15bSj_mayer
53e4bcb14cSths #define MAX_IDE_BUS 2
54271dd5e0Sblueswir1 #define CFG_ADDR 0xf0000510
55536d8cdaSAlexander Graf #define TBFREQ 16600000UL
569d1c1283SBALATON Zoltan #define CLOCKFREQ 266000000UL
579d1c1283SBALATON Zoltan #define BUSFREQ 66000000UL
58271dd5e0Sblueswir1
59b50de5cdSMark Cave-Ayland #define NDRV_VGA_FILENAME "qemu_vga.ndrv"
60b50de5cdSMark Cave-Ayland
613d0031c1SBALATON Zoltan #define PROM_FILENAME "openbios-ppc"
62464c73e8SBALATON Zoltan #define PROM_BASE 0xffc00000
63464c73e8SBALATON Zoltan #define PROM_SIZE (4 * MiB)
64a773e64aSMark Cave-Ayland
653d0031c1SBALATON Zoltan #define KERNEL_LOAD_ADDR 0x01000000
663d0031c1SBALATON Zoltan #define KERNEL_GAP 0x00100000
673d0031c1SBALATON Zoltan
683d0031c1SBALATON Zoltan #define GRACKLE_BASE 0xfec00000
693d0031c1SBALATON Zoltan
fw_cfg_boot_set(void * opaque,const char * boot_device,Error ** errp)70ddcd5531SGonglei static void fw_cfg_boot_set(void *opaque, const char *boot_device,
71ddcd5531SGonglei Error **errp)
72513f789fSblueswir1 {
7348779e50SGabriel L. Somlo fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
74513f789fSblueswir1 }
75513f789fSblueswir1
translate_kernel_address(void * opaque,uint64_t addr)76409dbce5SAurelien Jarno static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
77409dbce5SAurelien Jarno {
78409dbce5SAurelien Jarno return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR;
79409dbce5SAurelien Jarno }
80409dbce5SAurelien Jarno
ppc_heathrow_reset(void * opaque)811bba0dc9SAndreas Färber static void ppc_heathrow_reset(void *opaque)
821bba0dc9SAndreas Färber {
83cd79664fSAndreas Färber PowerPCCPU *cpu = opaque;
841bba0dc9SAndreas Färber
8530d0647bSNicholas Piggin cpu_ppc_tb_reset(&cpu->env);
86cd79664fSAndreas Färber cpu_reset(CPU(cpu));
871bba0dc9SAndreas Färber }
881bba0dc9SAndreas Färber
ppc_heathrow_init(MachineState * machine)893ef96221SMarcel Apfelbaum static void ppc_heathrow_init(MachineState *machine)
903cbee15bSj_mayer {
91cd7b9498SPaolo Bonzini const char *bios_name = machine->firmware ?: PROM_FILENAME;
92053b7086SThomas Huth MachineClass *mc = MACHINE_GET_CLASS(machine);
9372c33dd7SAndreas Färber PowerPCCPU *cpu = NULL;
94e2684c0bSAndreas Färber CPUPPCState *env = NULL;
955cea8590SPaul Brook char *filename;
966120dc8dSBALATON Zoltan int i, bios_size = -1;
97c92bb2c7SAvi Kivity MemoryRegion *bios = g_new(MemoryRegion, 1);
9894c92e1aSBALATON Zoltan uint64_t bios_addr;
996120dc8dSBALATON Zoltan uint32_t kernel_base = 0, initrd_base = 0, cmdline_base = 0;
1006120dc8dSBALATON Zoltan int32_t kernel_size = 0, initrd_size = 0;
1013cbee15bSj_mayer PCIBus *pci_bus;
10218e0383bSBALATON Zoltan Object *macio;
10307a7484eSAndreas Färber MACIOIDEState *macio_ide;
104a773e64aSMark Cave-Ayland SysBusDevice *s;
105370022ceSMark Cave-Ayland DeviceState *dev, *pic_dev, *grackle_dev;
106293c867dSAndreas Färber BusState *adb_bus;
107513f789fSblueswir1 uint16_t ppc_boot_device;
1085df3eb4dSBALATON Zoltan DriveInfo *dinfo, *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
109271dd5e0Sblueswir1 void *fw_cfg;
1106b924abeSBALATON Zoltan uint64_t tbfreq = kvm_enabled() ? kvmppc_get_tbfreq() : TBFREQ;
1113cbee15bSj_mayer
1123cbee15bSj_mayer /* init CPUs */
11394c92e1aSBALATON Zoltan for (i = 0; i < machine->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 */
12394c92e1aSBALATON Zoltan if (machine->ram_size > 2047 * MiB) {
124ab3dd749SPhilippe Mathieu-Daudé error_report("Too much memory for this machine: %" PRId64 " MB, "
12594c92e1aSBALATON Zoltan "maximum 2047 MB", machine->ram_size / MiB);
1266b4079f8Saurel32 exit(1);
1276b4079f8Saurel32 }
1286b4079f8Saurel32
129c3481ab0SBALATON Zoltan memory_region_add_subregion(get_system_memory(), 0, machine->ram);
130a748ab6dSaurel32
131464c73e8SBALATON Zoltan /* allocate and load firmware ROM */
132464c73e8SBALATON Zoltan memory_region_init_rom(bios, NULL, "ppc_heathrow.bios", PROM_SIZE,
133f8ed85acSMarkus Armbruster &error_fatal);
134c3481ab0SBALATON Zoltan memory_region_add_subregion(get_system_memory(), PROM_BASE, bios);
135e206ad48SHu Tao
1365cea8590SPaul Brook filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
1375cea8590SPaul Brook if (filename) {
138464c73e8SBALATON Zoltan /* Load OpenBIOS (ELF) */
139464c73e8SBALATON Zoltan bios_size = load_elf(filename, NULL, NULL, NULL, NULL, &bios_addr,
140adc1a4a2SPhilippe Mathieu-Daudé NULL, NULL, ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
141464c73e8SBALATON Zoltan /* Unfortunately, load_elf sign-extends reading elf32 */
142464c73e8SBALATON Zoltan bios_addr = (uint32_t)bios_addr;
143464c73e8SBALATON Zoltan
144464c73e8SBALATON Zoltan if (bios_size <= 0) {
145b8df3255SBALATON Zoltan /* or if could not load ELF try loading a binary ROM image */
146464c73e8SBALATON Zoltan bios_size = load_image_targphys(filename, PROM_BASE, PROM_SIZE);
147464c73e8SBALATON Zoltan bios_addr = PROM_BASE;
148464c73e8SBALATON Zoltan }
1497267c094SAnthony Liguori g_free(filename);
1505cea8590SPaul Brook }
151464c73e8SBALATON Zoltan if (bios_size < 0 || bios_addr - PROM_BASE + bios_size > PROM_SIZE) {
152c525436eSMarkus Armbruster error_report("could not load PowerPC bios '%s'", bios_name);
1533cbee15bSj_mayer exit(1);
1543cbee15bSj_mayer }
1553cbee15bSj_mayer
156b8df3255SBALATON Zoltan if (machine->kernel_filename) {
1573cbee15bSj_mayer kernel_base = KERNEL_LOAD_ADDR;
158b8df3255SBALATON Zoltan kernel_size = load_elf(machine->kernel_filename, NULL,
159617160c9SBALATON Zoltan translate_kernel_address, NULL, NULL, NULL,
160adc1a4a2SPhilippe Mathieu-Daudé NULL, NULL, ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
161cc537e13SBALATON Zoltan if (kernel_size < 0) {
162b8df3255SBALATON Zoltan kernel_size = load_aout(machine->kernel_filename, kernel_base,
16394c92e1aSBALATON Zoltan machine->ram_size - kernel_base,
164134ab17fSPaolo Bonzini true, TARGET_PAGE_SIZE);
165cc537e13SBALATON Zoltan }
166cc537e13SBALATON Zoltan if (kernel_size < 0) {
167b8df3255SBALATON Zoltan kernel_size = load_image_targphys(machine->kernel_filename,
16852f163b7Sblueswir1 kernel_base,
16994c92e1aSBALATON Zoltan machine->ram_size - kernel_base);
170cc537e13SBALATON Zoltan }
1713cbee15bSj_mayer if (kernel_size < 0) {
172b8df3255SBALATON Zoltan error_report("could not load kernel '%s'",
173b8df3255SBALATON Zoltan machine->kernel_filename);
1743cbee15bSj_mayer exit(1);
1753cbee15bSj_mayer }
1763cbee15bSj_mayer /* load initrd */
177b8df3255SBALATON Zoltan if (machine->initrd_filename) {
178b8df3255SBALATON Zoltan initrd_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size +
179b8df3255SBALATON Zoltan KERNEL_GAP);
180b8df3255SBALATON Zoltan initrd_size = load_image_targphys(machine->initrd_filename,
181b8df3255SBALATON Zoltan initrd_base,
18294c92e1aSBALATON Zoltan machine->ram_size - initrd_base);
1833cbee15bSj_mayer if (initrd_size < 0) {
184c525436eSMarkus Armbruster error_report("could not load initial ram disk '%s'",
185b8df3255SBALATON Zoltan machine->initrd_filename);
1863cbee15bSj_mayer exit(1);
1873cbee15bSj_mayer }
18839d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size);
1893cbee15bSj_mayer } else {
19039d96847SKamil Rytarowski cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP);
1913cbee15bSj_mayer }
1926ac0e82dSbalrog ppc_boot_device = 'm';
1933cbee15bSj_mayer } else {
19428c5af54Sj_mayer ppc_boot_device = '\0';
19594c92e1aSBALATON Zoltan for (i = 0; machine->boot_config.order[i] != '\0'; i++) {
19694c92e1aSBALATON Zoltan /*
19794c92e1aSBALATON Zoltan * TOFIX: for now, the second IDE channel is not properly
1980d913fdbSj_mayer * used by OHW. The Mac floppy disk are not emulated.
19928c5af54Sj_mayer * For now, OHW cannot boot from the network.
20028c5af54Sj_mayer */
20128c5af54Sj_mayer #if 0
20294c92e1aSBALATON Zoltan if (machine->boot_config.order[i] >= 'a' &&
20394c92e1aSBALATON Zoltan machine->boot_config.order[i] <= 'f') {
20494c92e1aSBALATON Zoltan ppc_boot_device = machine->boot_config.order[i];
20528c5af54Sj_mayer break;
2060d913fdbSj_mayer }
20728c5af54Sj_mayer #else
20894c92e1aSBALATON Zoltan if (machine->boot_config.order[i] >= 'c' &&
20994c92e1aSBALATON Zoltan machine->boot_config.order[i] <= 'd') {
21094c92e1aSBALATON Zoltan ppc_boot_device = machine->boot_config.order[i];
21128c5af54Sj_mayer break;
2120d913fdbSj_mayer }
21328c5af54Sj_mayer #endif
21428c5af54Sj_mayer }
21528c5af54Sj_mayer if (ppc_boot_device == '\0') {
2166f76b817SAlistair Francis error_report("No valid boot device for G3 Beige machine");
21728c5af54Sj_mayer exit(1);
21828c5af54Sj_mayer }
2193cbee15bSj_mayer }
2203cbee15bSj_mayer
22149ac51aeSMark Cave-Ayland /* Grackle PCI host bridge */
222370022ceSMark Cave-Ayland grackle_dev = qdev_new(TYPE_GRACKLE_PCI_HOST_BRIDGE);
223370022ceSMark Cave-Ayland qdev_prop_set_uint32(grackle_dev, "ofw-addr", 0x80000000);
224370022ceSMark Cave-Ayland s = SYS_BUS_DEVICE(grackle_dev);
22549ac51aeSMark Cave-Ayland sysbus_realize_and_unref(s, &error_fatal);
22649ac51aeSMark Cave-Ayland
22749ac51aeSMark Cave-Ayland sysbus_mmio_map(s, 0, GRACKLE_BASE);
22849ac51aeSMark Cave-Ayland sysbus_mmio_map(s, 1, GRACKLE_BASE + 0x200000);
22949ac51aeSMark Cave-Ayland /* PCI hole */
23049ac51aeSMark Cave-Ayland memory_region_add_subregion(get_system_memory(), 0x80000000ULL,
23149ac51aeSMark Cave-Ayland sysbus_mmio_get_region(s, 2));
23249ac51aeSMark Cave-Ayland /* Register 2 MB of ISA IO space */
23349ac51aeSMark Cave-Ayland memory_region_add_subregion(get_system_memory(), 0xfe000000,
23449ac51aeSMark Cave-Ayland sysbus_mmio_get_region(s, 3));
23549ac51aeSMark Cave-Ayland
236370022ceSMark Cave-Ayland pci_bus = PCI_HOST_BRIDGE(grackle_dev)->bus;
237370022ceSMark Cave-Ayland
238370022ceSMark Cave-Ayland /* MacIO */
23918e0383bSBALATON Zoltan macio = OBJECT(pci_new(PCI_DEVFN(16, 0), TYPE_OLDWORLD_MACIO));
24018e0383bSBALATON Zoltan qdev_prop_set_uint64(DEVICE(macio), "frequency", tbfreq);
241370022ceSMark Cave-Ayland
24218e0383bSBALATON Zoltan dev = DEVICE(object_resolve_path_component(macio, "escc"));
24318e0383bSBALATON Zoltan qdev_prop_set_chr(dev, "chrA", serial_hd(0));
24418e0383bSBALATON Zoltan qdev_prop_set_chr(dev, "chrB", serial_hd(1));
245370022ceSMark Cave-Ayland
2465df3eb4dSBALATON Zoltan dinfo = drive_get(IF_MTD, 0, 0);
2475df3eb4dSBALATON Zoltan if (dinfo) {
2485df3eb4dSBALATON Zoltan dev = DEVICE(object_resolve_path_component(macio, "nvram"));
2495df3eb4dSBALATON Zoltan qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo));
2505df3eb4dSBALATON Zoltan }
2515df3eb4dSBALATON Zoltan
25218e0383bSBALATON Zoltan pci_realize_and_unref(PCI_DEVICE(macio), pci_bus, &error_fatal);
253370022ceSMark Cave-Ayland
25418e0383bSBALATON Zoltan pic_dev = DEVICE(object_resolve_path_component(macio, "pic"));
255370022ceSMark Cave-Ayland for (i = 0; i < 4; i++) {
256370022ceSMark Cave-Ayland qdev_connect_gpio_out(grackle_dev, i,
257370022ceSMark Cave-Ayland qdev_get_gpio_in(pic_dev, 0x15 + i));
258370022ceSMark Cave-Ayland }
259a5ed75feSMark Cave-Ayland
2603cbee15bSj_mayer /* Connect the heathrow PIC outputs to the 6xx bus */
26194c92e1aSBALATON Zoltan for (i = 0; i < machine->smp.cpus; i++) {
2623cbee15bSj_mayer switch (PPC_INPUT(env)) {
2633cbee15bSj_mayer case PPC_FLAGS_INPUT_6xx:
264370022ceSMark Cave-Ayland /* XXX: we register only 1 output pin for heathrow PIC */
265a5ed75feSMark Cave-Ayland qdev_connect_gpio_out(pic_dev, 0,
2660f3e0c6fSCédric Le Goater qdev_get_gpio_in(DEVICE(cpu), PPC6xx_INPUT_INT));
2673cbee15bSj_mayer break;
2683cbee15bSj_mayer default:
269c525436eSMarkus Armbruster error_report("Bus model not supported on OldWorld Mac machine");
270c525436eSMarkus Armbruster exit(1);
2713cbee15bSj_mayer }
2723cbee15bSj_mayer }
2733cbee15bSj_mayer
2743e20ad3aSAurelien Jarno pci_vga_init(pci_bus);
2753cbee15bSj_mayer
27636b6968dSDavid Woodhouse pci_init_nic_devices(pci_bus, mc->default_nic);
277e4bcb14cSths
278370022ceSMark Cave-Ayland /* MacIO IDE */
279d8f94e1bSJohn Snow ide_drive_get(hd, ARRAY_SIZE(hd));
28018e0383bSBALATON Zoltan macio_ide = MACIO_IDE(object_resolve_path_component(macio, "ide[0]"));
28107a7484eSAndreas Färber macio_ide_init_drives(macio_ide, hd);
28207a7484eSAndreas Färber
28318e0383bSBALATON Zoltan macio_ide = MACIO_IDE(object_resolve_path_component(macio, "ide[1]"));
28414eefd0eSAlexander Graf macio_ide_init_drives(macio_ide, &hd[MAX_IDE_DEVS]);
2853cbee15bSj_mayer
286370022ceSMark Cave-Ayland /* MacIO CUDA/ADB */
28718e0383bSBALATON Zoltan dev = DEVICE(object_resolve_path_component(macio, "cuda"));
288293c867dSAndreas Färber adb_bus = qdev_get_child_bus(dev, "adb.0");
2893e80f690SMarkus Armbruster dev = qdev_new(TYPE_ADB_KEYBOARD);
2903e80f690SMarkus Armbruster qdev_realize_and_unref(dev, adb_bus, &error_fatal);
2913e80f690SMarkus Armbruster dev = qdev_new(TYPE_ADB_MOUSE);
2923e80f690SMarkus Armbruster qdev_realize_and_unref(dev, adb_bus, &error_fatal);
29345fa67fbSAndreas Färber
2944bcbe0b6SEduardo Habkost if (machine_usb(machine)) {
295afb9a60eSGerd Hoffmann pci_create_simple(pci_bus, -1, "pci-ohci");
2963cbee15bSj_mayer }
2973cbee15bSj_mayer
298cc537e13SBALATON Zoltan if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) {
2993cbee15bSj_mayer graphic_depth = 15;
300cc537e13SBALATON Zoltan }
3013cbee15bSj_mayer
3023cbee15bSj_mayer /* No PCI init: the BIOS will do it */
3033cbee15bSj_mayer
3043e80f690SMarkus Armbruster dev = qdev_new(TYPE_FW_CFG_MEM);
30581a07050SMark Cave-Ayland fw_cfg = FW_CFG(dev);
30681a07050SMark Cave-Ayland qdev_prop_set_uint32(dev, "data_width", 1);
30781a07050SMark Cave-Ayland qdev_prop_set_bit(dev, "dma_enabled", false);
3084db4847dSBALATON Zoltan object_property_add_child(OBJECT(machine), TYPE_FW_CFG, OBJECT(fw_cfg));
30981a07050SMark Cave-Ayland s = SYS_BUS_DEVICE(dev);
3103c6ef471SMarkus Armbruster sysbus_realize_and_unref(s, &error_fatal);
31181a07050SMark Cave-Ayland sysbus_mmio_map(s, 0, CFG_ADDR);
31281a07050SMark Cave-Ayland sysbus_mmio_map(s, 1, CFG_ADDR + 2);
31381a07050SMark Cave-Ayland
31494c92e1aSBALATON Zoltan fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)machine->smp.cpus);
315fe6b6346SLike Xu fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)machine->smp.max_cpus);
31694c92e1aSBALATON Zoltan fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)machine->ram_size);
317271dd5e0Sblueswir1 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW);
318513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
319513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
320b8df3255SBALATON Zoltan if (machine->kernel_cmdline) {
321b9e17a34SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
322b8df3255SBALATON Zoltan pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
323b8df3255SBALATON Zoltan machine->kernel_cmdline);
324513f789fSblueswir1 } else {
325513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
326513f789fSblueswir1 }
327513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
328513f789fSblueswir1 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
329513f789fSblueswir1 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device);
3307f1aec5fSLaurent Vivier
3317f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width);
3327f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height);
3337f1aec5fSLaurent Vivier fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth);
3347f1aec5fSLaurent Vivier
33545024f09SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled());
336dc333cd6SAlexander Graf if (kvm_enabled()) {
33745024f09SAlexander Graf uint8_t *hypercall;
33845024f09SAlexander Graf
3397267c094SAnthony Liguori hypercall = g_malloc(16);
34045024f09SAlexander Graf kvmppc_get_hypercall(env, hypercall, 16);
34145024f09SAlexander Graf fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16);
34245024f09SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid());
343dc333cd6SAlexander Graf }
344caae6c96SAlexander Graf fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, tbfreq);
345a1014f25SAlexander Graf /* Mac OS X requires a "known good" clock-frequency value; pass it one. */
3469d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_CLOCKFREQ, CLOCKFREQ);
3479d1c1283SBALATON Zoltan fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_BUSFREQ, BUSFREQ);
348dc333cd6SAlexander Graf
349b50de5cdSMark Cave-Ayland /* MacOS NDRV VGA driver */
350b50de5cdSMark Cave-Ayland filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, NDRV_VGA_FILENAME);
351b50de5cdSMark Cave-Ayland if (filename) {
3529776874fSPeter Maydell gchar *ndrv_file;
3539776874fSPeter Maydell gsize ndrv_size;
354b50de5cdSMark Cave-Ayland
3559776874fSPeter Maydell if (g_file_get_contents(filename, &ndrv_file, &ndrv_size, NULL)) {
356b50de5cdSMark Cave-Ayland fw_cfg_add_file(fw_cfg, "ndrv/qemu_vga.ndrv", ndrv_file, ndrv_size);
357b50de5cdSMark Cave-Ayland }
358b50de5cdSMark Cave-Ayland g_free(filename);
359b50de5cdSMark Cave-Ayland }
360b50de5cdSMark Cave-Ayland
361513f789fSblueswir1 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
3623cbee15bSj_mayer }
3633cbee15bSj_mayer
364bbcc635fSMark Cave-Ayland /*
365bbcc635fSMark Cave-Ayland * Implementation of an interface to adjust firmware path
366bbcc635fSMark Cave-Ayland * for the bootindex property handling.
367bbcc635fSMark Cave-Ayland */
heathrow_fw_dev_path(FWPathProvider * p,BusState * bus,DeviceState * dev)368bbcc635fSMark Cave-Ayland static char *heathrow_fw_dev_path(FWPathProvider *p, BusState *bus,
369bbcc635fSMark Cave-Ayland DeviceState *dev)
370bbcc635fSMark Cave-Ayland {
371bbcc635fSMark Cave-Ayland PCIDevice *pci;
372bbcc635fSMark Cave-Ayland MACIOIDEState *macio_ide;
373bbcc635fSMark Cave-Ayland
374bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "macio-oldworld")) {
375bbcc635fSMark Cave-Ayland pci = PCI_DEVICE(dev);
376bbcc635fSMark Cave-Ayland return g_strdup_printf("mac-io@%x", PCI_SLOT(pci->devfn));
377bbcc635fSMark Cave-Ayland }
378bbcc635fSMark Cave-Ayland
379bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "macio-ide")) {
380bbcc635fSMark Cave-Ayland macio_ide = MACIO_IDE(dev);
381bbcc635fSMark Cave-Ayland return g_strdup_printf("ata-3@%x", macio_ide->addr);
382bbcc635fSMark Cave-Ayland }
383bbcc635fSMark Cave-Ayland
384bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-hd")) {
385484d366eSMark Cave-Ayland return g_strdup("disk");
386bbcc635fSMark Cave-Ayland }
387bbcc635fSMark Cave-Ayland
388bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "ide-cd")) {
389bbcc635fSMark Cave-Ayland return g_strdup("cdrom");
390bbcc635fSMark Cave-Ayland }
391bbcc635fSMark Cave-Ayland
392bbcc635fSMark Cave-Ayland if (!strcmp(object_get_typename(OBJECT(dev)), "virtio-blk-device")) {
393bbcc635fSMark Cave-Ayland return g_strdup("disk");
394bbcc635fSMark Cave-Ayland }
395bbcc635fSMark Cave-Ayland
396bbcc635fSMark Cave-Ayland return NULL;
397bbcc635fSMark Cave-Ayland }
398bbcc635fSMark Cave-Ayland
heathrow_kvm_type(MachineState * machine,const char * arg)399dc0ca80eSEric Auger static int heathrow_kvm_type(MachineState *machine, const char *arg)
400277c7a4dSAlexander Graf {
401277c7a4dSAlexander Graf /* Always force PR KVM */
402277c7a4dSAlexander Graf return 2;
403277c7a4dSAlexander Graf }
404277c7a4dSAlexander Graf
heathrow_class_init(ObjectClass * oc,const void * data)40512d1a768SPhilippe Mathieu-Daudé static void heathrow_class_init(ObjectClass *oc, const void *data)
406e264d29dSEduardo Habkost {
407c8bd3526SMark Cave-Ayland MachineClass *mc = MACHINE_CLASS(oc);
408bbcc635fSMark Cave-Ayland FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc);
409c8bd3526SMark Cave-Ayland
4109d906ad1STejas Vipin mc->desc = "Heathrow based PowerMac";
411e264d29dSEduardo Habkost mc->init = ppc_heathrow_init;
4122059839bSMarkus Armbruster mc->block_default_type = IF_IDE;
41383234b82SPeter Maydell /* SMP is not supported currently */
41483234b82SPeter Maydell mc->max_cpus = 1;
41546214a27SAndreas Färber #ifndef TARGET_PPC64
416ea0ac7f6SPhilippe Mathieu-Daudé mc->is_default = true;
41746214a27SAndreas Färber #endif
418f309ae85SEduardo Habkost /* TOFIX "cad" when Mac floppy is implemented */
419e264d29dSEduardo Habkost mc->default_boot_order = "cd";
420e264d29dSEduardo Habkost mc->kvm_type = heathrow_kvm_type;
421f4c6604eSIgor Mammedov mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("750_v3.1");
4223232794bSMark Cave-Ayland mc->default_display = "std";
423053b7086SThomas Huth mc->default_nic = "ne2k_pci";
424bbcc635fSMark Cave-Ayland mc->ignore_boot_device_suffixes = true;
4258ee06e4cSIgor Mammedov mc->default_ram_id = "ppc_heathrow.ram";
426bbcc635fSMark Cave-Ayland fwc->get_dev_path = heathrow_fw_dev_path;
427f80f9ec9SAnthony Liguori }
428f80f9ec9SAnthony Liguori
429c8bd3526SMark Cave-Ayland static const TypeInfo ppc_heathrow_machine_info = {
430c8bd3526SMark Cave-Ayland .name = MACHINE_TYPE_NAME("g3beige"),
431c8bd3526SMark Cave-Ayland .parent = TYPE_MACHINE,
432bbcc635fSMark Cave-Ayland .class_init = heathrow_class_init,
433*2cd09e47SPhilippe Mathieu-Daudé .interfaces = (const InterfaceInfo[]) {
434bbcc635fSMark Cave-Ayland { TYPE_FW_PATH_PROVIDER },
435bbcc635fSMark Cave-Ayland { }
436bbcc635fSMark Cave-Ayland },
437c8bd3526SMark Cave-Ayland };
438c8bd3526SMark Cave-Ayland
ppc_heathrow_register_types(void)439c8bd3526SMark Cave-Ayland static void ppc_heathrow_register_types(void)
440c8bd3526SMark Cave-Ayland {
441c8bd3526SMark Cave-Ayland type_register_static(&ppc_heathrow_machine_info);
442c8bd3526SMark Cave-Ayland }
443c8bd3526SMark Cave-Ayland
444c8bd3526SMark Cave-Ayland type_init(ppc_heathrow_register_types);
445