blob: 7bb7ac39975f1ca1467249da9fe988905b901ef3 [file] [log] [blame]
bellard64201202004-05-26 22:55:16 +00001/*
j_mayer3cbee152007-10-28 23:42:18 +00002 * QEMU PowerPC CHRP (currently NewWorld PowerMac) hardware System Emulator
ths5fafdf22007-09-16 21:08:06 +00003 *
j_mayer47103572007-03-30 09:38:04 +00004 * Copyright (c) 2004-2007 Fabrice Bellard
j_mayer3cbee152007-10-28 23:42:18 +00005 * Copyright (c) 2007 Jocelyn Mayer
ths5fafdf22007-09-16 21:08:06 +00006 *
bellard64201202004-05-26 22:55:16 +00007 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
Alexander Graf915cd3a2010-02-09 17:37:03 +010024 *
25 * PCI bus layout on a real G5 (U3 based):
26 *
27 * 0000:f0:0b.0 Host bridge [0600]: Apple Computer Inc. U3 AGP [106b:004b]
28 * 0000:f0:10.0 VGA compatible controller [0300]: ATI Technologies Inc RV350 AP [Radeon 9600] [1002:4150]
29 * 0001:00:00.0 Host bridge [0600]: Apple Computer Inc. CPC945 HT Bridge [106b:004a]
30 * 0001:00:01.0 PCI bridge [0604]: Advanced Micro Devices [AMD] AMD-8131 PCI-X Bridge [1022:7450] (rev 12)
31 * 0001:00:02.0 PCI bridge [0604]: Advanced Micro Devices [AMD] AMD-8131 PCI-X Bridge [1022:7450] (rev 12)
32 * 0001:00:03.0 PCI bridge [0604]: Apple Computer Inc. K2 HT-PCI Bridge [106b:0045]
33 * 0001:00:04.0 PCI bridge [0604]: Apple Computer Inc. K2 HT-PCI Bridge [106b:0046]
34 * 0001:00:05.0 PCI bridge [0604]: Apple Computer Inc. K2 HT-PCI Bridge [106b:0047]
35 * 0001:00:06.0 PCI bridge [0604]: Apple Computer Inc. K2 HT-PCI Bridge [106b:0048]
36 * 0001:00:07.0 PCI bridge [0604]: Apple Computer Inc. K2 HT-PCI Bridge [106b:0049]
37 * 0001:01:07.0 Class [ff00]: Apple Computer Inc. K2 KeyLargo Mac/IO [106b:0041] (rev 20)
38 * 0001:01:08.0 USB Controller [0c03]: Apple Computer Inc. K2 KeyLargo USB [106b:0040]
39 * 0001:01:09.0 USB Controller [0c03]: Apple Computer Inc. K2 KeyLargo USB [106b:0040]
40 * 0001:02:0b.0 USB Controller [0c03]: NEC Corporation USB [1033:0035] (rev 43)
41 * 0001:02:0b.1 USB Controller [0c03]: NEC Corporation USB [1033:0035] (rev 43)
42 * 0001:02:0b.2 USB Controller [0c03]: NEC Corporation USB 2.0 [1033:00e0] (rev 04)
43 * 0001:03:0d.0 Class [ff00]: Apple Computer Inc. K2 ATA/100 [106b:0043]
44 * 0001:03:0e.0 FireWire (IEEE 1394) [0c00]: Apple Computer Inc. K2 FireWire [106b:0042]
45 * 0001:04:0f.0 Ethernet controller [0200]: Apple Computer Inc. K2 GMAC (Sun GEM) [106b:004c]
46 * 0001:05:0c.0 IDE interface [0101]: Broadcom K2 SATA [1166:0240]
bellard64201202004-05-26 22:55:16 +000047 */
Markus Armbrustera8d25322019-05-23 16:35:08 +020048
Peter Maydell0d755902016-01-26 18:16:58 +000049#include "qemu/osdep.h"
Markus Armbrustera8d25322019-05-23 16:35:08 +020050#include "qemu-common.h"
Paolo Bonzini2c65db52020-10-28 07:36:57 -040051#include "qemu/datadir.h"
Markus Armbrusterda34e652016-03-14 09:01:28 +010052#include "qapi/error.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010053#include "hw/ppc/ppc.h"
Markus Armbrustera27bd6c2019-08-12 07:23:51 +020054#include "hw/qdev-properties.h"
Andreas Färberbaec1912013-01-23 23:03:54 +000055#include "hw/ppc/mac.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010056#include "hw/input/adb.h"
57#include "hw/ppc/mac_dbdma.h"
Andreas Färberbaec1912013-01-23 23:03:54 +000058#include "hw/pci/pci.h"
Paolo Bonzini1422e322012-10-24 08:43:34 +020059#include "net/net.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010060#include "sysemu/sysemu.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010061#include "hw/nvram/fw_cfg.h"
62#include "hw/char/escc.h"
Mark Cave-Aylande1218e42018-02-28 20:32:37 +000063#include "hw/misc/macio/macio.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010064#include "hw/ppc/openpic.h"
Andreas Färberbaec1912013-01-23 23:03:54 +000065#include "hw/loader.h"
Mark Cave-Ayland5d19be62018-08-29 17:59:11 +010066#include "hw/fw-path-provider.h"
Blue Swirlca20cf32009-09-20 14:58:02 +000067#include "elf.h"
Markus Armbrusterc5254362015-12-17 17:35:09 +010068#include "qemu/error-report.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010069#include "sysemu/kvm.h"
Markus Armbruster71e8a912019-08-12 07:23:38 +020070#include "sysemu/reset.h"
Alexander Grafdc333cd2010-02-09 17:37:05 +010071#include "kvm_ppc.h"
Alexander Grafa2236d42010-02-09 17:37:08 +010072#include "hw/usb.h"
Andreas Färberbaec1912013-01-23 23:03:54 +000073#include "hw/sysbus.h"
Laurent Vivier5283c272017-02-10 10:27:22 +010074#include "trace.h"
bellard267002c2004-06-03 18:46:20 +000075
thse4bcb142007-12-02 04:51:10 +000076#define MAX_IDE_BUS 2
blueswir1006f3a42009-02-08 15:59:36 +000077#define CFG_ADDR 0xf0000510
Alexander Graf536d8cd2013-06-29 17:34:58 +020078#define TBFREQ (100UL * 1000UL * 1000UL)
Benjamin Herrenschmidt3c062282017-09-17 18:15:42 +010079#define CLOCKFREQ (900UL * 1000UL * 1000UL)
BALATON Zoltan9d1c1282014-04-17 19:04:44 +020080#define BUSFREQ (100UL * 1000UL * 1000UL)
thse4bcb142007-12-02 04:51:10 +000081
Mark Cave-Ayland53ecf092017-05-01 14:43:33 +010082#define NDRV_VGA_FILENAME "qemu_vga.ndrv"
83
BALATON Zoltan31a6f352020-10-16 01:47:17 +020084#define PROM_BASE 0xfff00000
85#define PROM_SIZE (1 * MiB)
bellard0aa6a4a2005-06-05 15:11:17 +000086
Gongleiddcd5532014-12-03 19:04:02 +000087static void fw_cfg_boot_set(void *opaque, const char *boot_device,
88 Error **errp)
blueswir1513f7892009-03-08 09:51:29 +000089{
Gabriel L. Somlo48779e52015-06-08 14:10:45 -040090 fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
blueswir1513f7892009-03-08 09:51:29 +000091}
92
Aurelien Jarno409dbce2010-03-14 21:20:59 +010093static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
94{
95 return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR;
96}
97
Andreas Färber1bba0dc2012-02-08 03:03:33 +010098static void ppc_core99_reset(void *opaque)
99{
Andreas Färber66809882012-05-04 17:30:25 +0200100 PowerPCCPU *cpu = opaque;
Andreas Färber1bba0dc2012-02-08 03:03:33 +0100101
Andreas Färber66809882012-05-04 17:30:25 +0200102 cpu_reset(CPU(cpu));
Alexander Graf20f649d2013-04-04 18:45:07 +0200103 /* 970 CPUs want to get their initial IP as part of their boot protocol */
BALATON Zoltan31a6f352020-10-16 01:47:17 +0200104 cpu->env.nip = PROM_BASE + 0x100;
Andreas Färber1bba0dc2012-02-08 03:03:33 +0100105}
106
j_mayer3cbee152007-10-28 23:42:18 +0000107/* PowerPC Mac99 hardware initialisation */
Marcel Apfelbaum3ef96222014-05-07 17:42:57 +0300108static void ppc_core99_init(MachineState *machine)
bellard64201202004-05-26 22:55:16 +0000109{
Marcel Apfelbaum3ef96222014-05-07 17:42:57 +0300110 ram_addr_t ram_size = machine->ram_size;
Paolo Bonzinicd7b9492020-10-26 10:30:23 -0400111 const char *bios_name = machine->firmware ?: PROM_FILENAME;
Marcel Apfelbaum3ef96222014-05-07 17:42:57 +0300112 const char *kernel_filename = machine->kernel_filename;
113 const char *kernel_cmdline = machine->kernel_cmdline;
114 const char *initrd_filename = machine->initrd_filename;
115 const char *boot_device = machine->boot_order;
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100116 Core99MachineState *core99_machine = CORE99_MACHINE(machine);
Andreas Färber8f8204e2012-05-04 17:29:07 +0200117 PowerPCCPU *cpu = NULL;
Andreas Färbere2684c02012-03-14 01:38:23 +0100118 CPUPPCState *env = NULL;
Paul Brook5cea8592009-05-30 00:52:44 +0100119 char *filename;
Greg Kurz99293012018-11-27 14:06:22 +0100120 IrqLines *openpic_irqs;
Alexander Grafd0b72632012-12-08 05:17:14 +0100121 int linux_boot, i, j, k;
Igor Mammedova5b5de02020-02-19 11:09:34 -0500122 MemoryRegion *bios = g_new(MemoryRegion, 1);
Avi Kivitya8170e52012-10-23 12:30:10 +0200123 hwaddr kernel_base, initrd_base, cmdline_base = 0;
Blue Swirl093209c2010-09-18 05:53:14 +0000124 long kernel_size, initrd_size;
Mark Cave-Aylandc90c3932018-03-06 20:31:00 +0000125 UNINHostState *uninorth_pci;
bellard46e50e92004-06-21 19:43:00 +0000126 PCIBus *pci_bus;
Markus Armbruster7d612262020-06-10 07:32:03 +0200127 PCIDevice *macio;
Mark Cave-Ayland348b8d12020-10-13 12:49:20 +0100128 ESCCState *escc;
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100129 bool has_pmu, has_adb;
Andreas Färber07a74842013-01-23 23:04:01 +0000130 MACIOIDEState *macio_ide;
Andreas Färber293c8672013-01-23 23:04:05 +0000131 BusState *adb_bus;
j_mayer3cbee152007-10-28 23:42:18 +0000132 MacIONVRAMState *nvr;
Peter Maydell97768742018-12-14 13:30:50 +0000133 int bios_size;
j_mayer28c5af52007-11-11 01:50:45 +0000134 int ppc_boot_device;
Gerd Hoffmannf455e982009-08-28 15:47:03 +0200135 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
blueswir1006f3a42009-02-08 15:59:36 +0000136 void *fw_cfg;
Alexander Graf0f921192010-02-09 17:37:02 +0100137 int machine_arch;
Alexander Grafd0b72632012-12-08 05:17:14 +0100138 SysBusDevice *s;
Mark Cave-Aylanddda12e92018-02-28 20:32:41 +0000139 DeviceState *dev, *pic_dev;
Mark Cave-Ayland6ce97b22020-12-29 17:56:16 +0000140 DeviceState *uninorth_internal_dev = NULL, *uninorth_agp_dev = NULL;
Alexander Graf261265c2014-07-11 03:24:39 +0200141 hwaddr nvram_addr = 0xFFF04000;
Alexander Grafcaae6c92014-07-13 22:29:02 +0200142 uint64_t tbfreq;
Like Xufe6b6342019-05-19 04:54:22 +0800143 unsigned int smp_cpus = machine->smp.cpus;
bellard46e50e92004-06-21 19:43:00 +0000144
bellard64201202004-05-26 22:55:16 +0000145 linux_boot = (kernel_filename != NULL);
146
bellardc68ea702005-11-21 23:33:12 +0000147 /* init CPUs */
j_mayere9df0142007-04-09 22:45:36 +0000148 for (i = 0; i < smp_cpus; i++) {
Igor Mammedov9dff4c02017-10-09 21:50:52 +0200149 cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
Andreas Färber8f8204e2012-05-04 17:29:07 +0200150 env = &cpu->env;
151
j_mayere9df0142007-04-09 22:45:36 +0000152 /* Set time-base frequency to 100 Mhz */
Alexander Graf536d8cd2013-06-29 17:34:58 +0200153 cpu_ppc_tb_init(env, TBFREQ);
Andreas Färber66809882012-05-04 17:30:25 +0200154 qemu_register_reset(ppc_core99_reset, cpu);
j_mayere9df0142007-04-09 22:45:36 +0000155 }
bellardc68ea702005-11-21 23:33:12 +0000156
bellard64201202004-05-26 22:55:16 +0000157 /* allocate RAM */
Philippe Mathieu-Daudé03b35422021-04-06 10:48:42 +0200158 if (machine->ram_size > 2 * GiB) {
159 error_report("RAM size more than 2 GiB is not supported");
160 exit(1);
161 }
Igor Mammedova5b5de02020-02-19 11:09:34 -0500162 memory_region_add_subregion(get_system_memory(), 0, machine->ram);
blueswir1864c1362009-02-05 20:20:29 +0000163
BALATON Zoltan31a6f352020-10-16 01:47:17 +0200164 /* allocate and load firmware ROM */
165 memory_region_init_rom(bios, NULL, "ppc_core99.bios", PROM_SIZE,
Markus Armbrusterf8ed85a2015-09-11 16:51:43 +0200166 &error_fatal);
BALATON Zoltan31a6f352020-10-16 01:47:17 +0200167 memory_region_add_subregion(get_system_memory(), PROM_BASE, bios);
Hu Taoe206ad42014-07-21 17:30:17 +0800168
Paul Brook5cea8592009-05-30 00:52:44 +0100169 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
Paul Brook5cea8592009-05-30 00:52:44 +0100170 if (filename) {
BALATON Zoltan31a6f352020-10-16 01:47:17 +0200171 /* Load OpenBIOS (ELF) */
Liam Merwick4366e1d2019-01-15 12:18:03 +0000172 bios_size = load_elf(filename, NULL, NULL, NULL, NULL,
Aleksandar Markovic6cdda0f2020-01-26 23:55:04 +0100173 NULL, NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
Blue Swirlca20cf32009-09-20 14:58:02 +0000174
BALATON Zoltan31a6f352020-10-16 01:47:17 +0200175 if (bios_size <= 0) {
176 /* or load binary ROM image */
177 bios_size = load_image_targphys(filename, PROM_BASE, PROM_SIZE);
178 }
Anthony Liguori7267c092011-08-20 22:09:37 -0500179 g_free(filename);
Paul Brook5cea8592009-05-30 00:52:44 +0100180 } else {
181 bios_size = -1;
182 }
BALATON Zoltan31a6f352020-10-16 01:47:17 +0200183 if (bios_size < 0 || bios_size > PROM_SIZE) {
Markus Armbrusterc5254362015-12-17 17:35:09 +0100184 error_report("could not load PowerPC bios '%s'", bios_name);
bellard64201202004-05-26 22:55:16 +0000185 exit(1);
186 }
ths3b46e622007-09-17 08:09:54 +0000187
bellardb6b8bd12004-06-21 16:55:53 +0000188 if (linux_boot) {
Blue Swirlca20cf32009-09-20 14:58:02 +0000189 int bswap_needed;
190
191#ifdef BSWAP_NEEDED
192 bswap_needed = 1;
193#else
194 bswap_needed = 0;
195#endif
bellardb6b8bd12004-06-21 16:55:53 +0000196 kernel_base = KERNEL_LOAD_ADDR;
blueswir1513f7892009-03-08 09:51:29 +0000197
Liam Merwick4366e1d2019-01-15 12:18:03 +0000198 kernel_size = load_elf(kernel_filename, NULL,
BALATON Zoltan617160c2020-07-05 19:22:11 +0200199 translate_kernel_address, NULL, NULL, NULL,
200 NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
blueswir1513f7892009-03-08 09:51:29 +0000201 if (kernel_size < 0)
202 kernel_size = load_aout(kernel_filename, kernel_base,
Blue Swirlca20cf32009-09-20 14:58:02 +0000203 ram_size - kernel_base, bswap_needed,
204 TARGET_PAGE_SIZE);
blueswir1513f7892009-03-08 09:51:29 +0000205 if (kernel_size < 0)
206 kernel_size = load_image_targphys(kernel_filename,
207 kernel_base,
208 ram_size - kernel_base);
bellardb6b8bd12004-06-21 16:55:53 +0000209 if (kernel_size < 0) {
Markus Armbrusterc5254362015-12-17 17:35:09 +0100210 error_report("could not load kernel '%s'", kernel_filename);
bellardb6b8bd12004-06-21 16:55:53 +0000211 exit(1);
212 }
213 /* load initrd */
214 if (initrd_filename) {
Kamil Rytarowski39d96842017-09-11 22:16:10 +0200215 initrd_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP);
pbrook44654492009-04-10 00:26:15 +0000216 initrd_size = load_image_targphys(initrd_filename, initrd_base,
217 ram_size - initrd_base);
bellardb6b8bd12004-06-21 16:55:53 +0000218 if (initrd_size < 0) {
Markus Armbrusterc5254362015-12-17 17:35:09 +0100219 error_report("could not load initial ram disk '%s'",
220 initrd_filename);
bellardb6b8bd12004-06-21 16:55:53 +0000221 exit(1);
222 }
Kamil Rytarowski39d96842017-09-11 22:16:10 +0200223 cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size);
bellardb6b8bd12004-06-21 16:55:53 +0000224 } else {
225 initrd_base = 0;
226 initrd_size = 0;
Kamil Rytarowski39d96842017-09-11 22:16:10 +0200227 cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP);
bellardb6b8bd12004-06-21 16:55:53 +0000228 }
balrog6ac0e822007-10-31 01:54:04 +0000229 ppc_boot_device = 'm';
bellardb6b8bd12004-06-21 16:55:53 +0000230 } else {
231 kernel_base = 0;
232 kernel_size = 0;
233 initrd_base = 0;
234 initrd_size = 0;
j_mayer28c5af52007-11-11 01:50:45 +0000235 ppc_boot_device = '\0';
236 /* We consider that NewWorld PowerMac never have any floppy drive
237 * For now, OHW cannot boot from the network.
238 */
j_mayer0d913fd2007-11-11 14:44:28 +0000239 for (i = 0; boot_device[i] != '\0'; i++) {
240 if (boot_device[i] >= 'c' && boot_device[i] <= 'f') {
241 ppc_boot_device = boot_device[i];
j_mayer28c5af52007-11-11 01:50:45 +0000242 break;
j_mayer0d913fd2007-11-11 14:44:28 +0000243 }
j_mayer28c5af52007-11-11 01:50:45 +0000244 }
245 if (ppc_boot_device == '\0') {
Alistair Francis6f76b812018-02-03 09:43:10 +0100246 error_report("No valid boot device for Mac99 machine");
j_mayer28c5af52007-11-11 01:50:45 +0000247 exit(1);
248 }
bellardb6b8bd12004-06-21 16:55:53 +0000249 }
bellard64201202004-05-26 22:55:16 +0000250
Mark Cave-Ayland06629462018-05-03 21:24:39 +0100251 /* UniN init */
Markus Armbruster3e80f692020-06-10 07:31:58 +0200252 dev = qdev_new(TYPE_UNI_NORTH);
Mark Cave-Ayland06629462018-05-03 21:24:39 +0100253 s = SYS_BUS_DEVICE(dev);
Markus Armbruster3c6ef472020-06-10 07:32:34 +0200254 sysbus_realize_and_unref(s, &error_fatal);
Mark Cave-Ayland06629462018-05-03 21:24:39 +0100255 memory_region_add_subregion(get_system_memory(), 0xf8000000,
256 sysbus_mmio_get_region(s, 0));
j_mayer3cbee152007-10-28 23:42:18 +0000257
Greg Kurz99293012018-11-27 14:06:22 +0100258 openpic_irqs = g_new0(IrqLines, smp_cpus);
j_mayer3cbee152007-10-28 23:42:18 +0000259 for (i = 0; i < smp_cpus; i++) {
260 /* Mac99 IRQ connection between OpenPIC outputs pins
261 * and PowerPC input pins
262 */
263 switch (PPC_INPUT(env)) {
264 case PPC_FLAGS_INPUT_6xx:
Greg Kurz99293012018-11-27 14:06:22 +0100265 openpic_irqs[i].irq[OPENPIC_OUTPUT_INT] =
j_mayer3cbee152007-10-28 23:42:18 +0000266 ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT];
Greg Kurz99293012018-11-27 14:06:22 +0100267 openpic_irqs[i].irq[OPENPIC_OUTPUT_CINT] =
j_mayer3cbee152007-10-28 23:42:18 +0000268 ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT];
Greg Kurz99293012018-11-27 14:06:22 +0100269 openpic_irqs[i].irq[OPENPIC_OUTPUT_MCK] =
j_mayer3cbee152007-10-28 23:42:18 +0000270 ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_MCP];
271 /* Not connected ? */
Greg Kurz99293012018-11-27 14:06:22 +0100272 openpic_irqs[i].irq[OPENPIC_OUTPUT_DEBUG] = NULL;
j_mayer3cbee152007-10-28 23:42:18 +0000273 /* Check this */
Greg Kurz99293012018-11-27 14:06:22 +0100274 openpic_irqs[i].irq[OPENPIC_OUTPUT_RESET] =
j_mayer3cbee152007-10-28 23:42:18 +0000275 ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_HRESET];
276 break;
277#if defined(TARGET_PPC64)
278 case PPC_FLAGS_INPUT_970:
Greg Kurz99293012018-11-27 14:06:22 +0100279 openpic_irqs[i].irq[OPENPIC_OUTPUT_INT] =
j_mayer3cbee152007-10-28 23:42:18 +0000280 ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT];
Greg Kurz99293012018-11-27 14:06:22 +0100281 openpic_irqs[i].irq[OPENPIC_OUTPUT_CINT] =
j_mayer3cbee152007-10-28 23:42:18 +0000282 ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT];
Greg Kurz99293012018-11-27 14:06:22 +0100283 openpic_irqs[i].irq[OPENPIC_OUTPUT_MCK] =
j_mayer3cbee152007-10-28 23:42:18 +0000284 ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_MCP];
285 /* Not connected ? */
Greg Kurz99293012018-11-27 14:06:22 +0100286 openpic_irqs[i].irq[OPENPIC_OUTPUT_DEBUG] = NULL;
j_mayer3cbee152007-10-28 23:42:18 +0000287 /* Check this */
Greg Kurz99293012018-11-27 14:06:22 +0100288 openpic_irqs[i].irq[OPENPIC_OUTPUT_RESET] =
j_mayer3cbee152007-10-28 23:42:18 +0000289 ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_HRESET];
290 break;
291#endif /* defined(TARGET_PPC64) */
292 default:
Markus Armbrusterc5254362015-12-17 17:35:09 +0100293 error_report("Bus model not supported on mac99 machine");
j_mayerdd37a5e2007-04-16 07:41:07 +0000294 exit(1);
295 }
bellard64201202004-05-26 22:55:16 +0000296 }
Alexander Grafd0b72632012-12-08 05:17:14 +0100297
Alexander Graf0f921192010-02-09 17:37:02 +0100298 if (PPC_INPUT(env) == PPC_FLAGS_INPUT_970) {
299 /* 970 gets a U3 bus */
Mark Cave-Ayland8ce3f742018-03-06 20:30:57 +0000300 /* Uninorth AGP bus */
Markus Armbruster3e80f692020-06-10 07:31:58 +0200301 dev = qdev_new(TYPE_U3_AGP_HOST_BRIDGE);
Markus Armbruster3c6ef472020-06-10 07:32:34 +0200302 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
Mark Cave-Ayland8ce3f742018-03-06 20:30:57 +0000303 uninorth_pci = U3_AGP_HOST_BRIDGE(dev);
304 s = SYS_BUS_DEVICE(dev);
305 /* PCI hole */
306 memory_region_add_subregion(get_system_memory(), 0x80000000ULL,
307 sysbus_mmio_get_region(s, 2));
Mark Cave-Aylande226efb2018-03-06 20:30:59 +0000308 /* Register 8 MB of ISA IO space */
309 memory_region_add_subregion(get_system_memory(), 0xf2000000,
310 sysbus_mmio_get_region(s, 3));
Mark Cave-Ayland8ce3f742018-03-06 20:30:57 +0000311 sysbus_mmio_map(s, 0, 0xf0800000);
312 sysbus_mmio_map(s, 1, 0xf0c00000);
313
Alexander Graf0f921192010-02-09 17:37:02 +0100314 machine_arch = ARCH_MAC99_U3;
315 } else {
Mark Cave-Ayland7b193182018-03-06 20:30:56 +0000316 /* Use values found on a real PowerMac */
317 /* Uninorth AGP bus */
Mark Cave-Ayland6ce97b22020-12-29 17:56:16 +0000318 uninorth_agp_dev = qdev_new(TYPE_UNI_NORTH_AGP_HOST_BRIDGE);
319 s = SYS_BUS_DEVICE(uninorth_agp_dev);
Markus Armbruster3c6ef472020-06-10 07:32:34 +0200320 sysbus_realize_and_unref(s, &error_fatal);
Mark Cave-Ayland7b193182018-03-06 20:30:56 +0000321 sysbus_mmio_map(s, 0, 0xf0800000);
322 sysbus_mmio_map(s, 1, 0xf0c00000);
323
324 /* Uninorth internal bus */
Mark Cave-Ayland6ce97b22020-12-29 17:56:16 +0000325 uninorth_internal_dev = qdev_new(
326 TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE);
327 s = SYS_BUS_DEVICE(uninorth_internal_dev);
Markus Armbruster3c6ef472020-06-10 07:32:34 +0200328 sysbus_realize_and_unref(s, &error_fatal);
Mark Cave-Ayland7b193182018-03-06 20:30:56 +0000329 sysbus_mmio_map(s, 0, 0xf4800000);
330 sysbus_mmio_map(s, 1, 0xf4c00000);
331
332 /* Uninorth main bus */
Markus Armbruster3e80f692020-06-10 07:31:58 +0200333 dev = qdev_new(TYPE_UNI_NORTH_PCI_HOST_BRIDGE);
Mark Cave-Ayland03756c82018-08-29 17:59:10 +0100334 qdev_prop_set_uint32(dev, "ofw-addr", 0xf2000000);
Markus Armbruster3c6ef472020-06-10 07:32:34 +0200335 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
Mark Cave-Ayland7b193182018-03-06 20:30:56 +0000336 uninorth_pci = UNI_NORTH_PCI_HOST_BRIDGE(dev);
337 s = SYS_BUS_DEVICE(dev);
338 /* PCI hole */
339 memory_region_add_subregion(get_system_memory(), 0x80000000ULL,
340 sysbus_mmio_get_region(s, 2));
Mark Cave-Aylande226efb2018-03-06 20:30:59 +0000341 /* Register 8 MB of ISA IO space */
342 memory_region_add_subregion(get_system_memory(), 0xf2000000,
343 sysbus_mmio_get_region(s, 3));
Mark Cave-Ayland7b193182018-03-06 20:30:56 +0000344 sysbus_mmio_map(s, 0, 0xf2800000);
345 sysbus_mmio_map(s, 1, 0xf2c00000);
346
Alexander Graf0f921192010-02-09 17:37:02 +0100347 machine_arch = ARCH_MAC99;
348 }
Alexander Grafcaae6c92014-07-13 22:29:02 +0200349
Alexander Graf72f1f972015-11-11 22:49:41 +0000350 machine->usb |= defaults_enabled() && !machine->usb_disabled;
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100351 has_pmu = (core99_machine->via_config != CORE99_VIA_CONFIG_CUDA);
352 has_adb = (core99_machine->via_config == CORE99_VIA_CONFIG_CUDA ||
353 core99_machine->via_config == CORE99_VIA_CONFIG_PMU_ADB);
Alexander Graf72f1f972015-11-11 22:49:41 +0000354
Alexander Grafcaae6c92014-07-13 22:29:02 +0200355 /* Timebase Frequency */
356 if (kvm_enabled()) {
357 tbfreq = kvmppc_get_tbfreq();
358 } else {
359 tbfreq = TBFREQ;
360 }
361
Mark Cave-Ayland0f4b5412018-03-06 20:30:50 +0000362 /* init basic PC hardware */
363 pci_bus = PCI_HOST_BRIDGE(uninorth_pci)->bus;
364
Mark Cave-Ayland343bd852018-02-28 20:32:33 +0000365 /* MacIO */
Markus Armbruster9307d062020-06-10 07:32:04 +0200366 macio = pci_new(-1, TYPE_NEWWORLD_MACIO);
Andreas Färber07a74842013-01-23 23:04:01 +0000367 dev = DEVICE(macio);
Alexander Grafb9812892014-07-13 22:31:53 +0200368 qdev_prop_set_uint64(dev, "frequency", tbfreq);
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100369 qdev_prop_set_bit(dev, "has-pmu", has_pmu);
370 qdev_prop_set_bit(dev, "has-adb", has_adb);
Mark Cave-Ayland348b8d12020-10-13 12:49:20 +0100371
372 escc = ESCC(object_resolve_path_component(OBJECT(macio), "escc"));
373 qdev_prop_set_chr(DEVICE(escc), "chrA", serial_hd(0));
374 qdev_prop_set_chr(DEVICE(escc), "chrB", serial_hd(1));
375
Markus Armbruster9307d062020-06-10 07:32:04 +0200376 pci_realize_and_unref(macio, pci_bus, &error_fatal);
Andreas Färber07a74842013-01-23 23:04:01 +0000377
Mark Cave-Ayland7e4d62d2020-12-29 17:56:17 +0000378 pic_dev = DEVICE(object_resolve_path_component(OBJECT(macio), "pic"));
Mark Cave-Ayland6ce97b22020-12-29 17:56:16 +0000379 for (i = 0; i < 4; i++) {
380 qdev_connect_gpio_out(DEVICE(uninorth_pci), i,
381 qdev_get_gpio_in(pic_dev, 0x1b + i));
382 }
383
384 /* TODO: additional PCI buses only wired up for 32-bit machines */
385 if (PPC_INPUT(env) != PPC_FLAGS_INPUT_970) {
386 /* Uninorth AGP bus */
387 for (i = 0; i < 4; i++) {
388 qdev_connect_gpio_out(uninorth_agp_dev, i,
389 qdev_get_gpio_in(pic_dev, 0x1b + i));
390 }
391
392 /* Uninorth internal bus */
393 for (i = 0; i < 4; i++) {
394 qdev_connect_gpio_out(uninorth_internal_dev, i,
395 qdev_get_gpio_in(pic_dev, 0x1b + i));
396 }
397 }
398
Mark Cave-Ayland7e4d62d2020-12-29 17:56:17 +0000399 /* OpenPIC */
400 s = SYS_BUS_DEVICE(pic_dev);
401 k = 0;
402 for (i = 0; i < smp_cpus; i++) {
403 for (j = 0; j < OPENPIC_OUTPUT_NB; j++) {
404 sysbus_connect_irq(s, k++, openpic_irqs[i].irq[j]);
405 }
406 }
407 g_free(openpic_irqs);
408
Andreas Färber07a74842013-01-23 23:04:01 +0000409 /* We only emulate 2 out of 3 IDE controllers for now */
John Snowd8f94e12014-10-01 14:19:27 -0400410 ide_drive_get(hd, ARRAY_SIZE(hd));
BALATON Zoltana0bb2a52014-06-24 00:03:48 +0200411
Andreas Färber07a74842013-01-23 23:04:01 +0000412 macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio),
413 "ide[0]"));
414 macio_ide_init_drives(macio_ide, hd);
415
416 macio_ide = MACIO_IDE(object_resolve_path_component(OBJECT(macio),
417 "ide[1]"));
418 macio_ide_init_drives(macio_ide, &hd[MAX_IDE_DEVS]);
pbrook0d92ed32006-05-21 16:30:15 +0000419
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100420 if (has_adb) {
Mark Cave-Aylandd811d612018-06-12 17:44:02 +0100421 if (has_pmu) {
422 dev = DEVICE(object_resolve_path_component(OBJECT(macio), "pmu"));
423 } else {
424 dev = DEVICE(object_resolve_path_component(OBJECT(macio), "cuda"));
425 }
426
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100427 adb_bus = qdev_get_child_bus(dev, "adb.0");
Markus Armbruster3e80f692020-06-10 07:31:58 +0200428 dev = qdev_new(TYPE_ADB_KEYBOARD);
Markus Armbruster3e80f692020-06-10 07:31:58 +0200429 qdev_realize_and_unref(dev, adb_bus, &error_fatal);
Mark Cave-Aylandd811d612018-06-12 17:44:02 +0100430
Markus Armbruster3e80f692020-06-10 07:31:58 +0200431 dev = qdev_new(TYPE_ADB_MOUSE);
Markus Armbruster3e80f692020-06-10 07:31:58 +0200432 qdev_realize_and_unref(dev, adb_bus, &error_fatal);
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100433 }
Andreas Färber45fa67f2013-01-23 23:04:02 +0000434
Marcel Apfelbaum59a04192015-01-06 15:29:17 +0200435 if (machine->usb) {
Gerd Hoffmannafb9a602012-03-07 15:06:32 +0100436 pci_create_simple(pci_bus, -1, "pci-ohci");
Markus Armbrusterc86580b2015-02-04 13:28:14 +0100437
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +0000438 /* U3 needs to use USB for input because Linux doesn't support via-cuda
439 on PPC64 */
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100440 if (!has_adb || machine_arch == ARCH_MAC99_U3) {
Markus Armbrusterc86580b2015-02-04 13:28:14 +0100441 USBBus *usb_bus = usb_bus_find(-1);
442
443 usb_create_simple(usb_bus, "usb-kbd");
444 usb_create_simple(usb_bus, "usb-mouse");
zhlcindy@gmail.com094b2872012-09-02 19:25:28 +0000445 }
Alexander Grafa2236d42010-02-09 17:37:08 +0100446 }
447
BALATON Zoltana0bb2a52014-06-24 00:03:48 +0200448 pci_vga_init(pci_bus);
449
450 if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) {
bellardb6b8bd12004-06-21 16:55:53 +0000451 graphic_depth = 15;
BALATON Zoltana0bb2a52014-06-24 00:03:48 +0200452 }
453
454 for (i = 0; i < nb_nics; i++) {
Mark Cave-Ayland4479b512019-02-08 17:22:01 +0000455 pci_nic_init_nofail(&nd_table[i], pci_bus, "sungem", NULL);
BALATON Zoltana0bb2a52014-06-24 00:03:48 +0200456 }
blueswir14f3f2382009-02-08 16:01:01 +0000457
j_mayer3cbee152007-10-28 23:42:18 +0000458 /* The NewWorld NVRAM is not located in the MacIO device */
Wei Yang038adc22019-10-13 10:11:45 +0800459 if (kvm_enabled() && qemu_real_host_page_size > 4096) {
Alexander Graf261265c2014-07-11 03:24:39 +0200460 /* We can't combine read-write and read-only in a single page, so
461 move the NVRAM out of ROM again for KVM */
462 nvram_addr = 0xFFE00000;
463 }
Markus Armbruster3e80f692020-06-10 07:31:58 +0200464 dev = qdev_new(TYPE_MACIO_NVRAM);
Andreas Färber95ed3b72013-01-23 23:04:00 +0000465 qdev_prop_set_uint32(dev, "size", 0x2000);
466 qdev_prop_set_uint32(dev, "it_shift", 1);
Markus Armbruster3c6ef472020-06-10 07:32:34 +0200467 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
Alexander Graf261265c2014-07-11 03:24:39 +0200468 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, nvram_addr);
Andreas Färber95ed3b72013-01-23 23:04:00 +0000469 nvr = MACIO_NVRAM(dev);
j_mayer3cbee152007-10-28 23:42:18 +0000470 pmac_format_nvram_partition(nvr, 0x2000);
bellardb6b8bd12004-06-21 16:55:53 +0000471 /* No PCI init: the BIOS will do it */
bellard0aa6a4a2005-06-05 15:11:17 +0000472
Markus Armbruster3e80f692020-06-10 07:31:58 +0200473 dev = qdev_new(TYPE_FW_CFG_MEM);
Mark Cave-Ayland74887ed2018-08-10 11:27:57 +0100474 fw_cfg = FW_CFG(dev);
475 qdev_prop_set_uint32(dev, "data_width", 1);
476 qdev_prop_set_bit(dev, "dma_enabled", false);
477 object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG,
Markus Armbrusterd2623122020-05-05 17:29:22 +0200478 OBJECT(fw_cfg));
Mark Cave-Ayland74887ed2018-08-10 11:27:57 +0100479 s = SYS_BUS_DEVICE(dev);
Markus Armbruster3c6ef472020-06-10 07:32:34 +0200480 sysbus_realize_and_unref(s, &error_fatal);
Mark Cave-Ayland74887ed2018-08-10 11:27:57 +0100481 sysbus_mmio_map(s, 0, CFG_ADDR);
482 sysbus_mmio_map(s, 1, CFG_ADDR + 2);
483
Igor Mammedov5836d162016-11-15 13:17:15 +0100484 fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
Like Xufe6b6342019-05-19 04:54:22 +0800485 fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)machine->smp.max_cpus);
blueswir1006f3a42009-02-08 15:59:36 +0000486 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
Alexander Graf0f921192010-02-09 17:37:02 +0100487 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, machine_arch);
blueswir1513f7892009-03-08 09:51:29 +0000488 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
489 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
490 if (kernel_cmdline) {
Alexander Grafb9e17a32011-06-15 23:27:19 +0200491 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
492 pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline);
blueswir1513f7892009-03-08 09:51:29 +0000493 } else {
494 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
495 }
496 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
497 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
498 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ppc_boot_device);
Blue Swirl10696b42009-08-08 10:47:15 +0000499
500 fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width);
501 fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height);
502 fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth);
503
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100504 fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_VIACONFIG, core99_machine->via_config);
505
Alexander Graf45024f02010-08-03 15:22:42 +0200506 fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled());
Alexander Grafdc333cd2010-02-09 17:37:05 +0100507 if (kvm_enabled()) {
Alexander Graf45024f02010-08-03 15:22:42 +0200508 uint8_t *hypercall;
509
Anthony Liguori7267c092011-08-20 22:09:37 -0500510 hypercall = g_malloc(16);
Alexander Graf45024f02010-08-03 15:22:42 +0200511 kvmppc_get_hypercall(env, hypercall, 16);
512 fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16);
513 fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid());
Alexander Grafdc333cd2010-02-09 17:37:05 +0100514 }
Alexander Grafcaae6c92014-07-13 22:29:02 +0200515 fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, tbfreq);
Alexander Grafa1014f22013-06-23 00:22:50 +0200516 /* Mac OS X requires a "known good" clock-frequency value; pass it one. */
BALATON Zoltan9d1c1282014-04-17 19:04:44 +0200517 fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_CLOCKFREQ, CLOCKFREQ);
518 fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_BUSFREQ, BUSFREQ);
Alexander Graf261265c2014-07-11 03:24:39 +0200519 fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_NVRAM_ADDR, nvram_addr);
Alexander Grafdc333cd2010-02-09 17:37:05 +0100520
Mark Cave-Ayland53ecf092017-05-01 14:43:33 +0100521 /* MacOS NDRV VGA driver */
522 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, NDRV_VGA_FILENAME);
523 if (filename) {
Peter Maydell97768742018-12-14 13:30:50 +0000524 gchar *ndrv_file;
525 gsize ndrv_size;
Mark Cave-Ayland53ecf092017-05-01 14:43:33 +0100526
Peter Maydell97768742018-12-14 13:30:50 +0000527 if (g_file_get_contents(filename, &ndrv_file, &ndrv_size, NULL)) {
Mark Cave-Ayland53ecf092017-05-01 14:43:33 +0100528 fw_cfg_add_file(fw_cfg, "ndrv/qemu_vga.ndrv", ndrv_file, ndrv_size);
529 }
530 g_free(filename);
531 }
532
blueswir1513f7892009-03-08 09:51:29 +0000533 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
j_mayeraae93662007-11-24 02:56:36 +0000534}
bellard0aa6a4a2005-06-05 15:11:17 +0000535
Mark Cave-Ayland5d19be62018-08-29 17:59:11 +0100536/*
537 * Implementation of an interface to adjust firmware path
538 * for the bootindex property handling.
539 */
540static char *core99_fw_dev_path(FWPathProvider *p, BusState *bus,
541 DeviceState *dev)
542{
543 PCIDevice *pci;
Mark Cave-Ayland5d19be62018-08-29 17:59:11 +0100544 MACIOIDEState *macio_ide;
545
546 if (!strcmp(object_get_typename(OBJECT(dev)), "macio-newworld")) {
547 pci = PCI_DEVICE(dev);
548 return g_strdup_printf("mac-io@%x", PCI_SLOT(pci->devfn));
549 }
550
551 if (!strcmp(object_get_typename(OBJECT(dev)), "macio-ide")) {
552 macio_ide = MACIO_IDE(dev);
553 return g_strdup_printf("ata-3@%x", macio_ide->addr);
554 }
555
Mark Cave-Ayland5d19be62018-08-29 17:59:11 +0100556 if (!strcmp(object_get_typename(OBJECT(dev)), "ide-hd")) {
Mark Cave-Ayland31bc6fa2019-03-07 21:20:58 +0000557 return g_strdup("disk");
Mark Cave-Ayland5d19be62018-08-29 17:59:11 +0100558 }
559
560 if (!strcmp(object_get_typename(OBJECT(dev)), "ide-cd")) {
561 return g_strdup("cdrom");
562 }
563
564 if (!strcmp(object_get_typename(OBJECT(dev)), "virtio-blk-device")) {
565 return g_strdup("disk");
566 }
567
568 return NULL;
569}
Eric Augerdc0ca802019-03-04 11:13:33 +0100570static int core99_kvm_type(MachineState *machine, const char *arg)
Alexander Graf277c7a42014-07-24 10:46:47 +0200571{
572 /* Always force PR KVM */
573 return 2;
574}
575
Marcel Apfelbaumb1c2fb92015-01-06 15:29:15 +0200576static void core99_machine_class_init(ObjectClass *oc, void *data)
Anthony Liguorif80f9ec2009-05-20 18:38:09 -0500577{
Marcel Apfelbaumb1c2fb92015-01-06 15:29:15 +0200578 MachineClass *mc = MACHINE_CLASS(oc);
Mark Cave-Ayland5d19be62018-08-29 17:59:11 +0100579 FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc);
Marcel Apfelbaumb1c2fb92015-01-06 15:29:15 +0200580
Marcel Apfelbaumb1c2fb92015-01-06 15:29:15 +0200581 mc->desc = "Mac99 based PowerMAC";
582 mc->init = ppc_core99_init;
Markus Armbruster20598392017-02-15 11:05:40 +0100583 mc->block_default_type = IF_IDE;
Marcel Apfelbaumb1c2fb92015-01-06 15:29:15 +0200584 mc->max_cpus = MAX_CPUS;
585 mc->default_boot_order = "cd";
Mark Cave-Ayland32327942018-07-03 20:10:43 +0100586 mc->default_display = "std";
Marcel Apfelbaumb1c2fb92015-01-06 15:29:15 +0200587 mc->kvm_type = core99_kvm_type;
Igor Mammedov9dff4c02017-10-09 21:50:52 +0200588#ifdef TARGET_PPC64
589 mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("970fx_v3.1");
590#else
591 mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("7400_v2.9");
592#endif
Igor Mammedova5b5de02020-02-19 11:09:34 -0500593 mc->default_ram_id = "ppc_core99.ram";
Mark Cave-Ayland5d19be62018-08-29 17:59:11 +0100594 mc->ignore_boot_device_suffixes = true;
595 fwc->get_dev_path = core99_fw_dev_path;
Anthony Liguorif80f9ec2009-05-20 18:38:09 -0500596}
597
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100598static char *core99_get_via_config(Object *obj, Error **errp)
599{
600 Core99MachineState *cms = CORE99_MACHINE(obj);
601
602 switch (cms->via_config) {
603 default:
604 case CORE99_VIA_CONFIG_CUDA:
605 return g_strdup("cuda");
606
607 case CORE99_VIA_CONFIG_PMU:
608 return g_strdup("pmu");
609
610 case CORE99_VIA_CONFIG_PMU_ADB:
611 return g_strdup("pmu-adb");
612 }
613}
614
615static void core99_set_via_config(Object *obj, const char *value, Error **errp)
616{
617 Core99MachineState *cms = CORE99_MACHINE(obj);
618
619 if (!strcmp(value, "cuda")) {
620 cms->via_config = CORE99_VIA_CONFIG_CUDA;
621 } else if (!strcmp(value, "pmu")) {
622 cms->via_config = CORE99_VIA_CONFIG_PMU;
623 } else if (!strcmp(value, "pmu-adb")) {
624 cms->via_config = CORE99_VIA_CONFIG_PMU_ADB;
625 } else {
626 error_setg(errp, "Invalid via value");
627 error_append_hint(errp, "Valid values are cuda, pmu, pmu-adb.\n");
628 }
629}
630
Mark Cave-Ayland06fe3a52018-06-12 17:43:56 +0100631static void core99_instance_init(Object *obj)
632{
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100633 Core99MachineState *cms = CORE99_MACHINE(obj);
634
635 /* Default via_config is CORE99_VIA_CONFIG_CUDA */
636 cms->via_config = CORE99_VIA_CONFIG_CUDA;
637 object_property_add_str(obj, "via", core99_get_via_config,
Markus Armbrusterd2623122020-05-05 17:29:22 +0200638 core99_set_via_config);
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100639 object_property_set_description(obj, "via",
640 "Set VIA configuration. "
Markus Armbruster7eecec72020-05-05 17:29:15 +0200641 "Valid values are cuda, pmu and pmu-adb");
Mark Cave-Aylandf1114c12018-06-12 17:43:57 +0100642
Mark Cave-Ayland06fe3a52018-06-12 17:43:56 +0100643 return;
644}
645
Marcel Apfelbaumb1c2fb92015-01-06 15:29:15 +0200646static const TypeInfo core99_machine_info = {
Eduardo Habkostc0f36512015-08-20 14:54:34 -0700647 .name = MACHINE_TYPE_NAME("mac99"),
Marcel Apfelbaumb1c2fb92015-01-06 15:29:15 +0200648 .parent = TYPE_MACHINE,
649 .class_init = core99_machine_class_init,
Mark Cave-Ayland06fe3a52018-06-12 17:43:56 +0100650 .instance_init = core99_instance_init,
Mark Cave-Ayland5d19be62018-08-29 17:59:11 +0100651 .instance_size = sizeof(Core99MachineState),
652 .interfaces = (InterfaceInfo[]) {
653 { TYPE_FW_PATH_PROVIDER },
654 { }
655 },
Marcel Apfelbaumb1c2fb92015-01-06 15:29:15 +0200656};
657
658static void mac_machine_register_types(void)
659{
660 type_register_static(&core99_machine_info);
661}
662
663type_init(mac_machine_register_types)