xref: /openbmc/qemu/hw/ppc/mac_oldworld.c (revision a53b931645183bd0c15dd19ae0708fc3c81ecf1d)
1baec1910SAndreas Färber 
2baec1910SAndreas Färber /*
3baec1910SAndreas Färber  * QEMU OldWorld PowerMac (currently ~G3 Beige) hardware System Emulator
4baec1910SAndreas Färber  *
5baec1910SAndreas Färber  * Copyright (c) 2004-2007 Fabrice Bellard
6baec1910SAndreas Färber  * Copyright (c) 2007 Jocelyn Mayer
7baec1910SAndreas Färber  *
8baec1910SAndreas Färber  * Permission is hereby granted, free of charge, to any person obtaining a copy
9baec1910SAndreas Färber  * of this software and associated documentation files (the "Software"), to deal
10baec1910SAndreas Färber  * in the Software without restriction, including without limitation the rights
11baec1910SAndreas Färber  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12baec1910SAndreas Färber  * copies of the Software, and to permit persons to whom the Software is
13baec1910SAndreas Färber  * furnished to do so, subject to the following conditions:
14baec1910SAndreas Färber  *
15baec1910SAndreas Färber  * The above copyright notice and this permission notice shall be included in
16baec1910SAndreas Färber  * all copies or substantial portions of the Software.
17baec1910SAndreas Färber  *
18baec1910SAndreas Färber  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19baec1910SAndreas Färber  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20baec1910SAndreas Färber  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21baec1910SAndreas Färber  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22baec1910SAndreas Färber  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23baec1910SAndreas Färber  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24baec1910SAndreas Färber  * THE SOFTWARE.
25baec1910SAndreas Färber  */
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"
33cfb47bfaSBALATON Zoltan #include "hw/boards.h"
340d09e41aSPaolo Bonzini #include "hw/input/adb.h"
35baec1910SAndreas Färber #include "sysemu/sysemu.h"
36baec1910SAndreas Färber #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"
4087e5a4f8SBALATON Zoltan #include "hw/pci-host/grackle.h"
410d09e41aSPaolo Bonzini #include "hw/nvram/fw_cfg.h"
420d09e41aSPaolo Bonzini #include "hw/char/escc.h"
43e1218e48SMark Cave-Ayland #include "hw/misc/macio/macio.h"
44baec1910SAndreas Färber #include "hw/loader.h"
45bbcc635fSMark Cave-Ayland #include "hw/fw-path-provider.h"
46baec1910SAndreas Färber #include "elf.h"
47c525436eSMarkus Armbruster #include "qemu/error-report.h"
48baec1910SAndreas Färber #include "sysemu/kvm.h"
4971e8a915SMarkus Armbruster #include "sysemu/reset.h"
50baec1910SAndreas Färber #include "kvm_ppc.h"
51baec1910SAndreas Färber 
52baec1910SAndreas Färber #define MAX_IDE_BUS 2
53baec1910SAndreas Färber #define CFG_ADDR 0xf0000510
54536d8cdaSAlexander Graf #define TBFREQ 16600000UL
559d1c1283SBALATON Zoltan #define CLOCKFREQ 266000000UL
569d1c1283SBALATON Zoltan #define BUSFREQ 66000000UL
57baec1910SAndreas Färber 
58b50de5cdSMark Cave-Ayland #define NDRV_VGA_FILENAME "qemu_vga.ndrv"
59b50de5cdSMark Cave-Ayland 
603d0031c1SBALATON Zoltan #define PROM_FILENAME "openbios-ppc"
61464c73e8SBALATON Zoltan #define PROM_BASE 0xffc00000
62464c73e8SBALATON Zoltan #define PROM_SIZE (4 * MiB)
63a773e64aSMark Cave-Ayland 
643d0031c1SBALATON Zoltan #define KERNEL_LOAD_ADDR 0x01000000
653d0031c1SBALATON Zoltan #define KERNEL_GAP       0x00100000
663d0031c1SBALATON Zoltan 
673d0031c1SBALATON Zoltan #define GRACKLE_BASE 0xfec00000
683d0031c1SBALATON Zoltan 
fw_cfg_boot_set(void * opaque,const char * boot_device,Error ** errp)69ddcd5531SGonglei static void fw_cfg_boot_set(void *opaque, const char *boot_device,
70ddcd5531SGonglei                             Error **errp)
71baec1910SAndreas Färber {
7248779e50SGabriel L. Somlo     fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
73baec1910SAndreas Färber }
74baec1910SAndreas Färber 
translate_kernel_address(void * opaque,uint64_t addr)75baec1910SAndreas Färber static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
76baec1910SAndreas Färber {
77baec1910SAndreas Färber     return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR;
78baec1910SAndreas Färber }
79baec1910SAndreas Färber 
ppc_heathrow_reset(void * opaque)80baec1910SAndreas Färber static void ppc_heathrow_reset(void *opaque)
81baec1910SAndreas Färber {
82baec1910SAndreas Färber     PowerPCCPU *cpu = opaque;
83baec1910SAndreas Färber 
8430d0647bSNicholas Piggin     cpu_ppc_tb_reset(&cpu->env);
85baec1910SAndreas Färber     cpu_reset(CPU(cpu));
86baec1910SAndreas Färber }
87baec1910SAndreas Färber 
ppc_heathrow_init(MachineState * machine)883ef96221SMarcel Apfelbaum static void ppc_heathrow_init(MachineState *machine)
89baec1910SAndreas Färber {
90cd7b9498SPaolo Bonzini     const char *bios_name = machine->firmware ?: PROM_FILENAME;
91053b7086SThomas Huth     MachineClass *mc = MACHINE_GET_CLASS(machine);
92baec1910SAndreas Färber     PowerPCCPU *cpu = NULL;
93baec1910SAndreas Färber     CPUPPCState *env = NULL;
94baec1910SAndreas Färber     char *filename;
956120dc8dSBALATON Zoltan     int i, bios_size = -1;
96baec1910SAndreas Färber     MemoryRegion *bios = g_new(MemoryRegion, 1);
9794c92e1aSBALATON Zoltan     uint64_t bios_addr;
986120dc8dSBALATON Zoltan     uint32_t kernel_base = 0, initrd_base = 0, cmdline_base = 0;
996120dc8dSBALATON Zoltan     int32_t kernel_size = 0, initrd_size = 0;
100baec1910SAndreas Färber     PCIBus *pci_bus;
10118e0383bSBALATON Zoltan     Object *macio;
10207a7484eSAndreas Färber     MACIOIDEState *macio_ide;
103a773e64aSMark Cave-Ayland     SysBusDevice *s;
104370022ceSMark Cave-Ayland     DeviceState *dev, *pic_dev, *grackle_dev;
105293c867dSAndreas Färber     BusState *adb_bus;
106baec1910SAndreas Färber     uint16_t ppc_boot_device;
1075df3eb4dSBALATON Zoltan     DriveInfo *dinfo, *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
108baec1910SAndreas Färber     void *fw_cfg;
1096b924abeSBALATON Zoltan     uint64_t tbfreq = kvm_enabled() ? kvmppc_get_tbfreq() : TBFREQ;
110baec1910SAndreas Färber 
111baec1910SAndreas Färber     /* init CPUs */
11294c92e1aSBALATON Zoltan     for (i = 0; i < machine->smp.cpus; i++) {
113f4c6604eSIgor Mammedov         cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
114baec1910SAndreas Färber         env = &cpu->env;
115baec1910SAndreas Färber 
116baec1910SAndreas Färber         /* Set time-base frequency to 16.6 Mhz */
117536d8cdaSAlexander Graf         cpu_ppc_tb_init(env,  TBFREQ);
118baec1910SAndreas Färber         qemu_register_reset(ppc_heathrow_reset, cpu);
119baec1910SAndreas Färber     }
120baec1910SAndreas Färber 
121baec1910SAndreas Färber     /* allocate RAM */
12294c92e1aSBALATON Zoltan     if (machine->ram_size > 2047 * MiB) {
123ab3dd749SPhilippe Mathieu-Daudé         error_report("Too much memory for this machine: %" PRId64 " MB, "
12494c92e1aSBALATON Zoltan                      "maximum 2047 MB", machine->ram_size / MiB);
125baec1910SAndreas Färber         exit(1);
126baec1910SAndreas Färber     }
127baec1910SAndreas Färber 
128c3481ab0SBALATON Zoltan     memory_region_add_subregion(get_system_memory(), 0, machine->ram);
129baec1910SAndreas Färber 
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 
135baec1910SAndreas Färber     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
136baec1910SAndreas Färber     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         }
148baec1910SAndreas Färber         g_free(filename);
149baec1910SAndreas Färber     }
150464c73e8SBALATON Zoltan     if (bios_size < 0 || bios_addr - PROM_BASE + bios_size > PROM_SIZE) {
151c525436eSMarkus Armbruster         error_report("could not load PowerPC bios '%s'", bios_name);
152baec1910SAndreas Färber         exit(1);
153baec1910SAndreas Färber     }
154baec1910SAndreas Färber 
155b8df3255SBALATON Zoltan     if (machine->kernel_filename) {
1566120dc8dSBALATON Zoltan         int bswap_needed = 0;
157baec1910SAndreas Färber 
158baec1910SAndreas Färber #ifdef BSWAP_NEEDED
159baec1910SAndreas Färber         bswap_needed = 1;
160baec1910SAndreas Färber #endif
161baec1910SAndreas Färber         kernel_base = KERNEL_LOAD_ADDR;
162b8df3255SBALATON Zoltan         kernel_size = load_elf(machine->kernel_filename, NULL,
163617160c9SBALATON Zoltan                                translate_kernel_address, NULL, NULL, NULL,
164617160c9SBALATON Zoltan                                NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
165cc537e13SBALATON Zoltan         if (kernel_size < 0) {
166b8df3255SBALATON Zoltan             kernel_size = load_aout(machine->kernel_filename, kernel_base,
16794c92e1aSBALATON Zoltan                                     machine->ram_size - kernel_base,
16894c92e1aSBALATON Zoltan                                     bswap_needed, TARGET_PAGE_SIZE);
169cc537e13SBALATON Zoltan         }
170cc537e13SBALATON Zoltan         if (kernel_size < 0) {
171b8df3255SBALATON Zoltan             kernel_size = load_image_targphys(machine->kernel_filename,
172baec1910SAndreas Färber                                               kernel_base,
17394c92e1aSBALATON Zoltan                                               machine->ram_size - kernel_base);
174cc537e13SBALATON Zoltan         }
175baec1910SAndreas Färber         if (kernel_size < 0) {
176b8df3255SBALATON Zoltan             error_report("could not load kernel '%s'",
177b8df3255SBALATON Zoltan                          machine->kernel_filename);
178baec1910SAndreas Färber             exit(1);
179baec1910SAndreas Färber         }
180baec1910SAndreas Färber         /* load initrd */
181b8df3255SBALATON Zoltan         if (machine->initrd_filename) {
182b8df3255SBALATON Zoltan             initrd_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size +
183b8df3255SBALATON Zoltan                                             KERNEL_GAP);
184b8df3255SBALATON Zoltan             initrd_size = load_image_targphys(machine->initrd_filename,
185b8df3255SBALATON Zoltan                                               initrd_base,
18694c92e1aSBALATON Zoltan                                               machine->ram_size - initrd_base);
187baec1910SAndreas Färber             if (initrd_size < 0) {
188c525436eSMarkus Armbruster                 error_report("could not load initial ram disk '%s'",
189b8df3255SBALATON Zoltan                              machine->initrd_filename);
190baec1910SAndreas Färber                 exit(1);
191baec1910SAndreas Färber             }
19239d96847SKamil Rytarowski             cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size);
193baec1910SAndreas Färber         } else {
19439d96847SKamil Rytarowski             cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP);
195baec1910SAndreas Färber         }
196baec1910SAndreas Färber         ppc_boot_device = 'm';
197baec1910SAndreas Färber     } else {
198baec1910SAndreas Färber         ppc_boot_device = '\0';
19994c92e1aSBALATON Zoltan         for (i = 0; machine->boot_config.order[i] != '\0'; i++) {
20094c92e1aSBALATON Zoltan             /*
20194c92e1aSBALATON Zoltan              * TOFIX: for now, the second IDE channel is not properly
202baec1910SAndreas Färber              *        used by OHW. The Mac floppy disk are not emulated.
203baec1910SAndreas Färber              *        For now, OHW cannot boot from the network.
204baec1910SAndreas Färber              */
205baec1910SAndreas Färber #if 0
20694c92e1aSBALATON Zoltan             if (machine->boot_config.order[i] >= 'a' &&
20794c92e1aSBALATON Zoltan                 machine->boot_config.order[i] <= 'f') {
20894c92e1aSBALATON Zoltan                 ppc_boot_device = machine->boot_config.order[i];
209baec1910SAndreas Färber                 break;
210baec1910SAndreas Färber             }
211baec1910SAndreas Färber #else
21294c92e1aSBALATON Zoltan             if (machine->boot_config.order[i] >= 'c' &&
21394c92e1aSBALATON Zoltan                 machine->boot_config.order[i] <= 'd') {
21494c92e1aSBALATON Zoltan                 ppc_boot_device = machine->boot_config.order[i];
215baec1910SAndreas Färber                 break;
216baec1910SAndreas Färber             }
217baec1910SAndreas Färber #endif
218baec1910SAndreas Färber         }
219baec1910SAndreas Färber         if (ppc_boot_device == '\0') {
2206f76b817SAlistair Francis             error_report("No valid boot device for G3 Beige machine");
221baec1910SAndreas Färber             exit(1);
222baec1910SAndreas Färber         }
223baec1910SAndreas Färber     }
224baec1910SAndreas Färber 
22549ac51aeSMark Cave-Ayland     /* Grackle PCI host bridge */
226370022ceSMark Cave-Ayland     grackle_dev = qdev_new(TYPE_GRACKLE_PCI_HOST_BRIDGE);
227370022ceSMark Cave-Ayland     qdev_prop_set_uint32(grackle_dev, "ofw-addr", 0x80000000);
228370022ceSMark Cave-Ayland     s = SYS_BUS_DEVICE(grackle_dev);
22949ac51aeSMark Cave-Ayland     sysbus_realize_and_unref(s, &error_fatal);
23049ac51aeSMark Cave-Ayland 
23149ac51aeSMark Cave-Ayland     sysbus_mmio_map(s, 0, GRACKLE_BASE);
23249ac51aeSMark Cave-Ayland     sysbus_mmio_map(s, 1, GRACKLE_BASE + 0x200000);
23349ac51aeSMark Cave-Ayland     /* PCI hole */
23449ac51aeSMark Cave-Ayland     memory_region_add_subregion(get_system_memory(), 0x80000000ULL,
23549ac51aeSMark Cave-Ayland                                 sysbus_mmio_get_region(s, 2));
23649ac51aeSMark Cave-Ayland     /* Register 2 MB of ISA IO space */
23749ac51aeSMark Cave-Ayland     memory_region_add_subregion(get_system_memory(), 0xfe000000,
23849ac51aeSMark Cave-Ayland                                 sysbus_mmio_get_region(s, 3));
23949ac51aeSMark Cave-Ayland 
240370022ceSMark Cave-Ayland     pci_bus = PCI_HOST_BRIDGE(grackle_dev)->bus;
241370022ceSMark Cave-Ayland 
242370022ceSMark Cave-Ayland     /* MacIO */
24318e0383bSBALATON Zoltan     macio = OBJECT(pci_new(PCI_DEVFN(16, 0), TYPE_OLDWORLD_MACIO));
24418e0383bSBALATON Zoltan     qdev_prop_set_uint64(DEVICE(macio), "frequency", tbfreq);
245370022ceSMark Cave-Ayland 
24618e0383bSBALATON Zoltan     dev = DEVICE(object_resolve_path_component(macio, "escc"));
24718e0383bSBALATON Zoltan     qdev_prop_set_chr(dev, "chrA", serial_hd(0));
24818e0383bSBALATON Zoltan     qdev_prop_set_chr(dev, "chrB", serial_hd(1));
249370022ceSMark Cave-Ayland 
2505df3eb4dSBALATON Zoltan     dinfo = drive_get(IF_MTD, 0, 0);
2515df3eb4dSBALATON Zoltan     if (dinfo) {
2525df3eb4dSBALATON Zoltan         dev = DEVICE(object_resolve_path_component(macio, "nvram"));
2535df3eb4dSBALATON Zoltan         qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo));
2545df3eb4dSBALATON Zoltan     }
2555df3eb4dSBALATON Zoltan 
25618e0383bSBALATON Zoltan     pci_realize_and_unref(PCI_DEVICE(macio), pci_bus, &error_fatal);
257370022ceSMark Cave-Ayland 
25818e0383bSBALATON Zoltan     pic_dev = DEVICE(object_resolve_path_component(macio, "pic"));
259370022ceSMark Cave-Ayland     for (i = 0; i < 4; i++) {
260370022ceSMark Cave-Ayland         qdev_connect_gpio_out(grackle_dev, i,
261370022ceSMark Cave-Ayland                               qdev_get_gpio_in(pic_dev, 0x15 + i));
262370022ceSMark Cave-Ayland     }
263a5ed75feSMark Cave-Ayland 
264baec1910SAndreas Färber     /* Connect the heathrow PIC outputs to the 6xx bus */
26594c92e1aSBALATON Zoltan     for (i = 0; i < machine->smp.cpus; i++) {
266baec1910SAndreas Färber         switch (PPC_INPUT(env)) {
267baec1910SAndreas Färber         case PPC_FLAGS_INPUT_6xx:
268370022ceSMark Cave-Ayland             /* XXX: we register only 1 output pin for heathrow PIC */
269a5ed75feSMark Cave-Ayland             qdev_connect_gpio_out(pic_dev, 0,
2700f3e0c6fSCédric Le Goater                               qdev_get_gpio_in(DEVICE(cpu), PPC6xx_INPUT_INT));
271baec1910SAndreas Färber             break;
272baec1910SAndreas Färber         default:
273c525436eSMarkus Armbruster             error_report("Bus model not supported on OldWorld Mac machine");
274c525436eSMarkus Armbruster             exit(1);
275baec1910SAndreas Färber         }
276baec1910SAndreas Färber     }
277baec1910SAndreas Färber 
278baec1910SAndreas Färber     pci_vga_init(pci_bus);
279baec1910SAndreas Färber 
28036b6968dSDavid Woodhouse     pci_init_nic_devices(pci_bus, mc->default_nic);
281baec1910SAndreas Färber 
282370022ceSMark Cave-Ayland     /* MacIO IDE */
283d8f94e1bSJohn Snow     ide_drive_get(hd, ARRAY_SIZE(hd));
28418e0383bSBALATON Zoltan     macio_ide = MACIO_IDE(object_resolve_path_component(macio, "ide[0]"));
28507a7484eSAndreas Färber     macio_ide_init_drives(macio_ide, hd);
28607a7484eSAndreas Färber 
28718e0383bSBALATON Zoltan     macio_ide = MACIO_IDE(object_resolve_path_component(macio, "ide[1]"));
28814eefd0eSAlexander Graf     macio_ide_init_drives(macio_ide, &hd[MAX_IDE_DEVS]);
289baec1910SAndreas Färber 
290370022ceSMark Cave-Ayland     /* MacIO CUDA/ADB */
29118e0383bSBALATON Zoltan     dev = DEVICE(object_resolve_path_component(macio, "cuda"));
292293c867dSAndreas Färber     adb_bus = qdev_get_child_bus(dev, "adb.0");
2933e80f690SMarkus Armbruster     dev = qdev_new(TYPE_ADB_KEYBOARD);
2943e80f690SMarkus Armbruster     qdev_realize_and_unref(dev, adb_bus, &error_fatal);
2953e80f690SMarkus Armbruster     dev = qdev_new(TYPE_ADB_MOUSE);
2963e80f690SMarkus Armbruster     qdev_realize_and_unref(dev, adb_bus, &error_fatal);
29745fa67fbSAndreas Färber 
2984bcbe0b6SEduardo Habkost     if (machine_usb(machine)) {
299baec1910SAndreas Färber         pci_create_simple(pci_bus, -1, "pci-ohci");
300baec1910SAndreas Färber     }
301baec1910SAndreas Färber 
302cc537e13SBALATON Zoltan     if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) {
303baec1910SAndreas Färber         graphic_depth = 15;
304cc537e13SBALATON Zoltan     }
305baec1910SAndreas Färber 
306baec1910SAndreas Färber     /* No PCI init: the BIOS will do it */
307baec1910SAndreas Färber 
3083e80f690SMarkus Armbruster     dev = qdev_new(TYPE_FW_CFG_MEM);
30981a07050SMark Cave-Ayland     fw_cfg = FW_CFG(dev);
31081a07050SMark Cave-Ayland     qdev_prop_set_uint32(dev, "data_width", 1);
31181a07050SMark Cave-Ayland     qdev_prop_set_bit(dev, "dma_enabled", false);
3124db4847dSBALATON Zoltan     object_property_add_child(OBJECT(machine), TYPE_FW_CFG, OBJECT(fw_cfg));
31381a07050SMark Cave-Ayland     s = SYS_BUS_DEVICE(dev);
3143c6ef471SMarkus Armbruster     sysbus_realize_and_unref(s, &error_fatal);
31581a07050SMark Cave-Ayland     sysbus_mmio_map(s, 0, CFG_ADDR);
31681a07050SMark Cave-Ayland     sysbus_mmio_map(s, 1, CFG_ADDR + 2);
31781a07050SMark Cave-Ayland 
31894c92e1aSBALATON Zoltan     fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)machine->smp.cpus);
319fe6b6346SLike Xu     fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)machine->smp.max_cpus);
32094c92e1aSBALATON Zoltan     fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)machine->ram_size);
321baec1910SAndreas Färber     fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW);
322baec1910SAndreas Färber     fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
323baec1910SAndreas Färber     fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
324b8df3255SBALATON Zoltan     if (machine->kernel_cmdline) {
325baec1910SAndreas Färber         fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
326b8df3255SBALATON Zoltan         pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
327b8df3255SBALATON Zoltan                          machine->kernel_cmdline);
328baec1910SAndreas Färber     } else {
329baec1910SAndreas Färber         fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
330baec1910SAndreas Färber     }
331baec1910SAndreas Färber     fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
332baec1910SAndreas Färber     fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
333baec1910SAndreas Färber     fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device);
334baec1910SAndreas Färber 
335baec1910SAndreas Färber     fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width);
336baec1910SAndreas Färber     fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height);
337baec1910SAndreas Färber     fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth);
338baec1910SAndreas Färber 
339baec1910SAndreas Färber     fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled());
340baec1910SAndreas Färber     if (kvm_enabled()) {
341baec1910SAndreas Färber         uint8_t *hypercall;
342baec1910SAndreas Färber 
343baec1910SAndreas Färber         hypercall = g_malloc(16);
344baec1910SAndreas Färber         kvmppc_get_hypercall(env, hypercall, 16);
345baec1910SAndreas Färber         fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16);
346baec1910SAndreas Färber         fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid());
347baec1910SAndreas Färber     }
348caae6c96SAlexander Graf     fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, tbfreq);
349a1014f25SAlexander Graf     /* Mac OS X requires a "known good" clock-frequency value; pass it one. */
3509d1c1283SBALATON Zoltan     fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_CLOCKFREQ, CLOCKFREQ);
3519d1c1283SBALATON Zoltan     fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_BUSFREQ, BUSFREQ);
352baec1910SAndreas Färber 
353b50de5cdSMark Cave-Ayland     /* MacOS NDRV VGA driver */
354b50de5cdSMark Cave-Ayland     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, NDRV_VGA_FILENAME);
355b50de5cdSMark Cave-Ayland     if (filename) {
3569776874fSPeter Maydell         gchar *ndrv_file;
3579776874fSPeter Maydell         gsize ndrv_size;
358b50de5cdSMark Cave-Ayland 
3599776874fSPeter Maydell         if (g_file_get_contents(filename, &ndrv_file, &ndrv_size, NULL)) {
360b50de5cdSMark Cave-Ayland             fw_cfg_add_file(fw_cfg, "ndrv/qemu_vga.ndrv", ndrv_file, ndrv_size);
361b50de5cdSMark Cave-Ayland         }
362b50de5cdSMark Cave-Ayland         g_free(filename);
363b50de5cdSMark Cave-Ayland     }
364b50de5cdSMark Cave-Ayland 
365baec1910SAndreas Färber     qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
366baec1910SAndreas Färber }
367baec1910SAndreas Färber 
368bbcc635fSMark Cave-Ayland /*
369bbcc635fSMark Cave-Ayland  * Implementation of an interface to adjust firmware path
370bbcc635fSMark Cave-Ayland  * for the bootindex property handling.
371bbcc635fSMark Cave-Ayland  */
heathrow_fw_dev_path(FWPathProvider * p,BusState * bus,DeviceState * dev)372bbcc635fSMark Cave-Ayland static char *heathrow_fw_dev_path(FWPathProvider *p, BusState *bus,
373bbcc635fSMark Cave-Ayland                                   DeviceState *dev)
374bbcc635fSMark Cave-Ayland {
375bbcc635fSMark Cave-Ayland     PCIDevice *pci;
376bbcc635fSMark Cave-Ayland     MACIOIDEState *macio_ide;
377bbcc635fSMark Cave-Ayland 
378bbcc635fSMark Cave-Ayland     if (!strcmp(object_get_typename(OBJECT(dev)), "macio-oldworld")) {
379bbcc635fSMark Cave-Ayland         pci = PCI_DEVICE(dev);
380bbcc635fSMark Cave-Ayland         return g_strdup_printf("mac-io@%x", PCI_SLOT(pci->devfn));
381bbcc635fSMark Cave-Ayland     }
382bbcc635fSMark Cave-Ayland 
383bbcc635fSMark Cave-Ayland     if (!strcmp(object_get_typename(OBJECT(dev)), "macio-ide")) {
384bbcc635fSMark Cave-Ayland         macio_ide = MACIO_IDE(dev);
385bbcc635fSMark Cave-Ayland         return g_strdup_printf("ata-3@%x", macio_ide->addr);
386bbcc635fSMark Cave-Ayland     }
387bbcc635fSMark Cave-Ayland 
388bbcc635fSMark Cave-Ayland     if (!strcmp(object_get_typename(OBJECT(dev)), "ide-hd")) {
389484d366eSMark Cave-Ayland         return g_strdup("disk");
390bbcc635fSMark Cave-Ayland     }
391bbcc635fSMark Cave-Ayland 
392bbcc635fSMark Cave-Ayland     if (!strcmp(object_get_typename(OBJECT(dev)), "ide-cd")) {
393bbcc635fSMark Cave-Ayland         return g_strdup("cdrom");
394bbcc635fSMark Cave-Ayland     }
395bbcc635fSMark Cave-Ayland 
396bbcc635fSMark Cave-Ayland     if (!strcmp(object_get_typename(OBJECT(dev)), "virtio-blk-device")) {
397bbcc635fSMark Cave-Ayland         return g_strdup("disk");
398bbcc635fSMark Cave-Ayland     }
399bbcc635fSMark Cave-Ayland 
400bbcc635fSMark Cave-Ayland     return NULL;
401bbcc635fSMark Cave-Ayland }
402bbcc635fSMark Cave-Ayland 
heathrow_kvm_type(MachineState * machine,const char * arg)403dc0ca80eSEric Auger static int heathrow_kvm_type(MachineState *machine, const char *arg)
404277c7a4dSAlexander Graf {
405277c7a4dSAlexander Graf     /* Always force PR KVM */
406277c7a4dSAlexander Graf     return 2;
407277c7a4dSAlexander Graf }
408277c7a4dSAlexander Graf 
heathrow_class_init(ObjectClass * oc,void * data)409c8bd3526SMark Cave-Ayland static void heathrow_class_init(ObjectClass *oc, void *data)
410e264d29dSEduardo Habkost {
411c8bd3526SMark Cave-Ayland     MachineClass *mc = MACHINE_CLASS(oc);
412bbcc635fSMark Cave-Ayland     FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc);
413c8bd3526SMark Cave-Ayland 
414*9d906ad1STejas Vipin     mc->desc = "Heathrow based PowerMac";
415e264d29dSEduardo Habkost     mc->init = ppc_heathrow_init;
4162059839bSMarkus Armbruster     mc->block_default_type = IF_IDE;
41783234b82SPeter Maydell     /* SMP is not supported currently */
41883234b82SPeter Maydell     mc->max_cpus = 1;
419baec1910SAndreas Färber #ifndef TARGET_PPC64
420ea0ac7f6SPhilippe Mathieu-Daudé     mc->is_default = true;
421baec1910SAndreas Färber #endif
422f309ae85SEduardo Habkost     /* TOFIX "cad" when Mac floppy is implemented */
423e264d29dSEduardo Habkost     mc->default_boot_order = "cd";
424e264d29dSEduardo Habkost     mc->kvm_type = heathrow_kvm_type;
425f4c6604eSIgor Mammedov     mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("750_v3.1");
4263232794bSMark Cave-Ayland     mc->default_display = "std";
427053b7086SThomas Huth     mc->default_nic = "ne2k_pci";
428bbcc635fSMark Cave-Ayland     mc->ignore_boot_device_suffixes = true;
4298ee06e4cSIgor Mammedov     mc->default_ram_id = "ppc_heathrow.ram";
430bbcc635fSMark Cave-Ayland     fwc->get_dev_path = heathrow_fw_dev_path;
431baec1910SAndreas Färber }
432baec1910SAndreas Färber 
433c8bd3526SMark Cave-Ayland static const TypeInfo ppc_heathrow_machine_info = {
434c8bd3526SMark Cave-Ayland     .name          = MACHINE_TYPE_NAME("g3beige"),
435c8bd3526SMark Cave-Ayland     .parent        = TYPE_MACHINE,
436bbcc635fSMark Cave-Ayland     .class_init    = heathrow_class_init,
437bbcc635fSMark Cave-Ayland     .interfaces = (InterfaceInfo[]) {
438bbcc635fSMark Cave-Ayland         { TYPE_FW_PATH_PROVIDER },
439bbcc635fSMark Cave-Ayland         { }
440bbcc635fSMark Cave-Ayland     },
441c8bd3526SMark Cave-Ayland };
442c8bd3526SMark Cave-Ayland 
ppc_heathrow_register_types(void)443c8bd3526SMark Cave-Ayland static void ppc_heathrow_register_types(void)
444c8bd3526SMark Cave-Ayland {
445c8bd3526SMark Cave-Ayland     type_register_static(&ppc_heathrow_machine_info);
446c8bd3526SMark Cave-Ayland }
447c8bd3526SMark Cave-Ayland 
448c8bd3526SMark Cave-Ayland type_init(ppc_heathrow_register_types);
449