bellard | 6420120 | 2004-05-26 22:55:16 +0000 | [diff] [blame] | 1 | /* |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 2 | * QEMU PowerPC CHRP (currently NewWorld PowerMac) hardware System Emulator |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
j_mayer | 4710357 | 2007-03-30 09:38:04 +0000 | [diff] [blame] | 4 | * Copyright (c) 2004-2007 Fabrice Bellard |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 5 | * Copyright (c) 2007 Jocelyn Mayer |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 6 | * |
bellard | 6420120 | 2004-05-26 22:55:16 +0000 | [diff] [blame] | 7 | * 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 Graf | 915cd3a | 2010-02-09 17:37:03 +0100 | [diff] [blame] | 24 | * |
| 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] |
bellard | 6420120 | 2004-05-26 22:55:16 +0000 | [diff] [blame] | 47 | */ |
Markus Armbruster | a8d2532 | 2019-05-23 16:35:08 +0200 | [diff] [blame] | 48 | |
Peter Maydell | 0d75590 | 2016-01-26 18:16:58 +0000 | [diff] [blame] | 49 | #include "qemu/osdep.h" |
Markus Armbruster | a8d2532 | 2019-05-23 16:35:08 +0200 | [diff] [blame] | 50 | #include "qemu-common.h" |
Paolo Bonzini | 2c65db5 | 2020-10-28 07:36:57 -0400 | [diff] [blame] | 51 | #include "qemu/datadir.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 52 | #include "qapi/error.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 53 | #include "hw/ppc/ppc.h" |
Markus Armbruster | a27bd6c | 2019-08-12 07:23:51 +0200 | [diff] [blame] | 54 | #include "hw/qdev-properties.h" |
Andreas Färber | baec191 | 2013-01-23 23:03:54 +0000 | [diff] [blame] | 55 | #include "hw/ppc/mac.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 56 | #include "hw/input/adb.h" |
| 57 | #include "hw/ppc/mac_dbdma.h" |
Andreas Färber | baec191 | 2013-01-23 23:03:54 +0000 | [diff] [blame] | 58 | #include "hw/pci/pci.h" |
Paolo Bonzini | 1422e32 | 2012-10-24 08:43:34 +0200 | [diff] [blame] | 59 | #include "net/net.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 60 | #include "sysemu/sysemu.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 61 | #include "hw/nvram/fw_cfg.h" |
| 62 | #include "hw/char/escc.h" |
Mark Cave-Ayland | e1218e4 | 2018-02-28 20:32:37 +0000 | [diff] [blame] | 63 | #include "hw/misc/macio/macio.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 64 | #include "hw/ppc/openpic.h" |
Andreas Färber | baec191 | 2013-01-23 23:03:54 +0000 | [diff] [blame] | 65 | #include "hw/loader.h" |
Mark Cave-Ayland | 5d19be6 | 2018-08-29 17:59:11 +0100 | [diff] [blame] | 66 | #include "hw/fw-path-provider.h" |
Blue Swirl | ca20cf3 | 2009-09-20 14:58:02 +0000 | [diff] [blame] | 67 | #include "elf.h" |
Markus Armbruster | c525436 | 2015-12-17 17:35:09 +0100 | [diff] [blame] | 68 | #include "qemu/error-report.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 69 | #include "sysemu/kvm.h" |
Markus Armbruster | 71e8a91 | 2019-08-12 07:23:38 +0200 | [diff] [blame] | 70 | #include "sysemu/reset.h" |
Alexander Graf | dc333cd | 2010-02-09 17:37:05 +0100 | [diff] [blame] | 71 | #include "kvm_ppc.h" |
Alexander Graf | a2236d4 | 2010-02-09 17:37:08 +0100 | [diff] [blame] | 72 | #include "hw/usb.h" |
Andreas Färber | baec191 | 2013-01-23 23:03:54 +0000 | [diff] [blame] | 73 | #include "hw/sysbus.h" |
Laurent Vivier | 5283c27 | 2017-02-10 10:27:22 +0100 | [diff] [blame] | 74 | #include "trace.h" |
bellard | 267002c | 2004-06-03 18:46:20 +0000 | [diff] [blame] | 75 | |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 76 | #define MAX_IDE_BUS 2 |
blueswir1 | 006f3a4 | 2009-02-08 15:59:36 +0000 | [diff] [blame] | 77 | #define CFG_ADDR 0xf0000510 |
Alexander Graf | 536d8cd | 2013-06-29 17:34:58 +0200 | [diff] [blame] | 78 | #define TBFREQ (100UL * 1000UL * 1000UL) |
Benjamin Herrenschmidt | 3c06228 | 2017-09-17 18:15:42 +0100 | [diff] [blame] | 79 | #define CLOCKFREQ (900UL * 1000UL * 1000UL) |
BALATON Zoltan | 9d1c128 | 2014-04-17 19:04:44 +0200 | [diff] [blame] | 80 | #define BUSFREQ (100UL * 1000UL * 1000UL) |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 81 | |
Mark Cave-Ayland | 53ecf09 | 2017-05-01 14:43:33 +0100 | [diff] [blame] | 82 | #define NDRV_VGA_FILENAME "qemu_vga.ndrv" |
| 83 | |
BALATON Zoltan | 31a6f35 | 2020-10-16 01:47:17 +0200 | [diff] [blame] | 84 | #define PROM_BASE 0xfff00000 |
| 85 | #define PROM_SIZE (1 * MiB) |
bellard | 0aa6a4a | 2005-06-05 15:11:17 +0000 | [diff] [blame] | 86 | |
Gonglei | ddcd553 | 2014-12-03 19:04:02 +0000 | [diff] [blame] | 87 | static void fw_cfg_boot_set(void *opaque, const char *boot_device, |
| 88 | Error **errp) |
blueswir1 | 513f789 | 2009-03-08 09:51:29 +0000 | [diff] [blame] | 89 | { |
Gabriel L. Somlo | 48779e5 | 2015-06-08 14:10:45 -0400 | [diff] [blame] | 90 | fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); |
blueswir1 | 513f789 | 2009-03-08 09:51:29 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Aurelien Jarno | 409dbce | 2010-03-14 21:20:59 +0100 | [diff] [blame] | 93 | static uint64_t translate_kernel_address(void *opaque, uint64_t addr) |
| 94 | { |
| 95 | return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR; |
| 96 | } |
| 97 | |
Andreas Färber | 1bba0dc | 2012-02-08 03:03:33 +0100 | [diff] [blame] | 98 | static void ppc_core99_reset(void *opaque) |
| 99 | { |
Andreas Färber | 6680988 | 2012-05-04 17:30:25 +0200 | [diff] [blame] | 100 | PowerPCCPU *cpu = opaque; |
Andreas Färber | 1bba0dc | 2012-02-08 03:03:33 +0100 | [diff] [blame] | 101 | |
Andreas Färber | 6680988 | 2012-05-04 17:30:25 +0200 | [diff] [blame] | 102 | cpu_reset(CPU(cpu)); |
Alexander Graf | 20f649d | 2013-04-04 18:45:07 +0200 | [diff] [blame] | 103 | /* 970 CPUs want to get their initial IP as part of their boot protocol */ |
BALATON Zoltan | 31a6f35 | 2020-10-16 01:47:17 +0200 | [diff] [blame] | 104 | cpu->env.nip = PROM_BASE + 0x100; |
Andreas Färber | 1bba0dc | 2012-02-08 03:03:33 +0100 | [diff] [blame] | 105 | } |
| 106 | |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 107 | /* PowerPC Mac99 hardware initialisation */ |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 108 | static void ppc_core99_init(MachineState *machine) |
bellard | 6420120 | 2004-05-26 22:55:16 +0000 | [diff] [blame] | 109 | { |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 110 | ram_addr_t ram_size = machine->ram_size; |
Paolo Bonzini | cd7b949 | 2020-10-26 10:30:23 -0400 | [diff] [blame] | 111 | const char *bios_name = machine->firmware ?: PROM_FILENAME; |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 112 | 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-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 116 | Core99MachineState *core99_machine = CORE99_MACHINE(machine); |
Andreas Färber | 8f8204e | 2012-05-04 17:29:07 +0200 | [diff] [blame] | 117 | PowerPCCPU *cpu = NULL; |
Andreas Färber | e2684c0 | 2012-03-14 01:38:23 +0100 | [diff] [blame] | 118 | CPUPPCState *env = NULL; |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 119 | char *filename; |
Greg Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 120 | IrqLines *openpic_irqs; |
Alexander Graf | d0b7263 | 2012-12-08 05:17:14 +0100 | [diff] [blame] | 121 | int linux_boot, i, j, k; |
Igor Mammedov | a5b5de0 | 2020-02-19 11:09:34 -0500 | [diff] [blame] | 122 | MemoryRegion *bios = g_new(MemoryRegion, 1); |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 123 | hwaddr kernel_base, initrd_base, cmdline_base = 0; |
Blue Swirl | 093209c | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 124 | long kernel_size, initrd_size; |
Mark Cave-Ayland | c90c393 | 2018-03-06 20:31:00 +0000 | [diff] [blame] | 125 | UNINHostState *uninorth_pci; |
bellard | 46e50e9 | 2004-06-21 19:43:00 +0000 | [diff] [blame] | 126 | PCIBus *pci_bus; |
Markus Armbruster | 7d61226 | 2020-06-10 07:32:03 +0200 | [diff] [blame] | 127 | PCIDevice *macio; |
Mark Cave-Ayland | 348b8d1 | 2020-10-13 12:49:20 +0100 | [diff] [blame] | 128 | ESCCState *escc; |
Mark Cave-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 129 | bool has_pmu, has_adb; |
Andreas Färber | 07a7484 | 2013-01-23 23:04:01 +0000 | [diff] [blame] | 130 | MACIOIDEState *macio_ide; |
Andreas Färber | 293c867 | 2013-01-23 23:04:05 +0000 | [diff] [blame] | 131 | BusState *adb_bus; |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 132 | MacIONVRAMState *nvr; |
Peter Maydell | 9776874 | 2018-12-14 13:30:50 +0000 | [diff] [blame] | 133 | int bios_size; |
j_mayer | 28c5af5 | 2007-11-11 01:50:45 +0000 | [diff] [blame] | 134 | int ppc_boot_device; |
Gerd Hoffmann | f455e98 | 2009-08-28 15:47:03 +0200 | [diff] [blame] | 135 | DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; |
blueswir1 | 006f3a4 | 2009-02-08 15:59:36 +0000 | [diff] [blame] | 136 | void *fw_cfg; |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 137 | int machine_arch; |
Alexander Graf | d0b7263 | 2012-12-08 05:17:14 +0100 | [diff] [blame] | 138 | SysBusDevice *s; |
Mark Cave-Ayland | dda12e9 | 2018-02-28 20:32:41 +0000 | [diff] [blame] | 139 | DeviceState *dev, *pic_dev; |
Mark Cave-Ayland | 6ce97b2 | 2020-12-29 17:56:16 +0000 | [diff] [blame] | 140 | DeviceState *uninorth_internal_dev = NULL, *uninorth_agp_dev = NULL; |
Alexander Graf | 261265c | 2014-07-11 03:24:39 +0200 | [diff] [blame] | 141 | hwaddr nvram_addr = 0xFFF04000; |
Alexander Graf | caae6c9 | 2014-07-13 22:29:02 +0200 | [diff] [blame] | 142 | uint64_t tbfreq; |
Like Xu | fe6b634 | 2019-05-19 04:54:22 +0800 | [diff] [blame] | 143 | unsigned int smp_cpus = machine->smp.cpus; |
bellard | 46e50e9 | 2004-06-21 19:43:00 +0000 | [diff] [blame] | 144 | |
bellard | 6420120 | 2004-05-26 22:55:16 +0000 | [diff] [blame] | 145 | linux_boot = (kernel_filename != NULL); |
| 146 | |
bellard | c68ea70 | 2005-11-21 23:33:12 +0000 | [diff] [blame] | 147 | /* init CPUs */ |
j_mayer | e9df014 | 2007-04-09 22:45:36 +0000 | [diff] [blame] | 148 | for (i = 0; i < smp_cpus; i++) { |
Igor Mammedov | 9dff4c0 | 2017-10-09 21:50:52 +0200 | [diff] [blame] | 149 | cpu = POWERPC_CPU(cpu_create(machine->cpu_type)); |
Andreas Färber | 8f8204e | 2012-05-04 17:29:07 +0200 | [diff] [blame] | 150 | env = &cpu->env; |
| 151 | |
j_mayer | e9df014 | 2007-04-09 22:45:36 +0000 | [diff] [blame] | 152 | /* Set time-base frequency to 100 Mhz */ |
Alexander Graf | 536d8cd | 2013-06-29 17:34:58 +0200 | [diff] [blame] | 153 | cpu_ppc_tb_init(env, TBFREQ); |
Andreas Färber | 6680988 | 2012-05-04 17:30:25 +0200 | [diff] [blame] | 154 | qemu_register_reset(ppc_core99_reset, cpu); |
j_mayer | e9df014 | 2007-04-09 22:45:36 +0000 | [diff] [blame] | 155 | } |
bellard | c68ea70 | 2005-11-21 23:33:12 +0000 | [diff] [blame] | 156 | |
bellard | 6420120 | 2004-05-26 22:55:16 +0000 | [diff] [blame] | 157 | /* allocate RAM */ |
Philippe Mathieu-Daudé | 03b3542 | 2021-04-06 10:48:42 +0200 | [diff] [blame] | 158 | if (machine->ram_size > 2 * GiB) { |
| 159 | error_report("RAM size more than 2 GiB is not supported"); |
| 160 | exit(1); |
| 161 | } |
Igor Mammedov | a5b5de0 | 2020-02-19 11:09:34 -0500 | [diff] [blame] | 162 | memory_region_add_subregion(get_system_memory(), 0, machine->ram); |
blueswir1 | 864c136 | 2009-02-05 20:20:29 +0000 | [diff] [blame] | 163 | |
BALATON Zoltan | 31a6f35 | 2020-10-16 01:47:17 +0200 | [diff] [blame] | 164 | /* allocate and load firmware ROM */ |
| 165 | memory_region_init_rom(bios, NULL, "ppc_core99.bios", PROM_SIZE, |
Markus Armbruster | f8ed85a | 2015-09-11 16:51:43 +0200 | [diff] [blame] | 166 | &error_fatal); |
BALATON Zoltan | 31a6f35 | 2020-10-16 01:47:17 +0200 | [diff] [blame] | 167 | memory_region_add_subregion(get_system_memory(), PROM_BASE, bios); |
Hu Tao | e206ad4 | 2014-07-21 17:30:17 +0800 | [diff] [blame] | 168 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 169 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 170 | if (filename) { |
BALATON Zoltan | 31a6f35 | 2020-10-16 01:47:17 +0200 | [diff] [blame] | 171 | /* Load OpenBIOS (ELF) */ |
Liam Merwick | 4366e1d | 2019-01-15 12:18:03 +0000 | [diff] [blame] | 172 | bios_size = load_elf(filename, NULL, NULL, NULL, NULL, |
Aleksandar Markovic | 6cdda0f | 2020-01-26 23:55:04 +0100 | [diff] [blame] | 173 | NULL, NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0); |
Blue Swirl | ca20cf3 | 2009-09-20 14:58:02 +0000 | [diff] [blame] | 174 | |
BALATON Zoltan | 31a6f35 | 2020-10-16 01:47:17 +0200 | [diff] [blame] | 175 | if (bios_size <= 0) { |
| 176 | /* or load binary ROM image */ |
| 177 | bios_size = load_image_targphys(filename, PROM_BASE, PROM_SIZE); |
| 178 | } |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 179 | g_free(filename); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 180 | } else { |
| 181 | bios_size = -1; |
| 182 | } |
BALATON Zoltan | 31a6f35 | 2020-10-16 01:47:17 +0200 | [diff] [blame] | 183 | if (bios_size < 0 || bios_size > PROM_SIZE) { |
Markus Armbruster | c525436 | 2015-12-17 17:35:09 +0100 | [diff] [blame] | 184 | error_report("could not load PowerPC bios '%s'", bios_name); |
bellard | 6420120 | 2004-05-26 22:55:16 +0000 | [diff] [blame] | 185 | exit(1); |
| 186 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 187 | |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 188 | if (linux_boot) { |
Blue Swirl | ca20cf3 | 2009-09-20 14:58:02 +0000 | [diff] [blame] | 189 | int bswap_needed; |
| 190 | |
| 191 | #ifdef BSWAP_NEEDED |
| 192 | bswap_needed = 1; |
| 193 | #else |
| 194 | bswap_needed = 0; |
| 195 | #endif |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 196 | kernel_base = KERNEL_LOAD_ADDR; |
blueswir1 | 513f789 | 2009-03-08 09:51:29 +0000 | [diff] [blame] | 197 | |
Liam Merwick | 4366e1d | 2019-01-15 12:18:03 +0000 | [diff] [blame] | 198 | kernel_size = load_elf(kernel_filename, NULL, |
BALATON Zoltan | 617160c | 2020-07-05 19:22:11 +0200 | [diff] [blame] | 199 | translate_kernel_address, NULL, NULL, NULL, |
| 200 | NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0); |
blueswir1 | 513f789 | 2009-03-08 09:51:29 +0000 | [diff] [blame] | 201 | if (kernel_size < 0) |
| 202 | kernel_size = load_aout(kernel_filename, kernel_base, |
Blue Swirl | ca20cf3 | 2009-09-20 14:58:02 +0000 | [diff] [blame] | 203 | ram_size - kernel_base, bswap_needed, |
| 204 | TARGET_PAGE_SIZE); |
blueswir1 | 513f789 | 2009-03-08 09:51:29 +0000 | [diff] [blame] | 205 | if (kernel_size < 0) |
| 206 | kernel_size = load_image_targphys(kernel_filename, |
| 207 | kernel_base, |
| 208 | ram_size - kernel_base); |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 209 | if (kernel_size < 0) { |
Markus Armbruster | c525436 | 2015-12-17 17:35:09 +0100 | [diff] [blame] | 210 | error_report("could not load kernel '%s'", kernel_filename); |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 211 | exit(1); |
| 212 | } |
| 213 | /* load initrd */ |
| 214 | if (initrd_filename) { |
Kamil Rytarowski | 39d9684 | 2017-09-11 22:16:10 +0200 | [diff] [blame] | 215 | initrd_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP); |
pbrook | 4465449 | 2009-04-10 00:26:15 +0000 | [diff] [blame] | 216 | initrd_size = load_image_targphys(initrd_filename, initrd_base, |
| 217 | ram_size - initrd_base); |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 218 | if (initrd_size < 0) { |
Markus Armbruster | c525436 | 2015-12-17 17:35:09 +0100 | [diff] [blame] | 219 | error_report("could not load initial ram disk '%s'", |
| 220 | initrd_filename); |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 221 | exit(1); |
| 222 | } |
Kamil Rytarowski | 39d9684 | 2017-09-11 22:16:10 +0200 | [diff] [blame] | 223 | cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size); |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 224 | } else { |
| 225 | initrd_base = 0; |
| 226 | initrd_size = 0; |
Kamil Rytarowski | 39d9684 | 2017-09-11 22:16:10 +0200 | [diff] [blame] | 227 | cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP); |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 228 | } |
balrog | 6ac0e82 | 2007-10-31 01:54:04 +0000 | [diff] [blame] | 229 | ppc_boot_device = 'm'; |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 230 | } else { |
| 231 | kernel_base = 0; |
| 232 | kernel_size = 0; |
| 233 | initrd_base = 0; |
| 234 | initrd_size = 0; |
j_mayer | 28c5af5 | 2007-11-11 01:50:45 +0000 | [diff] [blame] | 235 | 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_mayer | 0d913fd | 2007-11-11 14:44:28 +0000 | [diff] [blame] | 239 | 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_mayer | 28c5af5 | 2007-11-11 01:50:45 +0000 | [diff] [blame] | 242 | break; |
j_mayer | 0d913fd | 2007-11-11 14:44:28 +0000 | [diff] [blame] | 243 | } |
j_mayer | 28c5af5 | 2007-11-11 01:50:45 +0000 | [diff] [blame] | 244 | } |
| 245 | if (ppc_boot_device == '\0') { |
Alistair Francis | 6f76b81 | 2018-02-03 09:43:10 +0100 | [diff] [blame] | 246 | error_report("No valid boot device for Mac99 machine"); |
j_mayer | 28c5af5 | 2007-11-11 01:50:45 +0000 | [diff] [blame] | 247 | exit(1); |
| 248 | } |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 249 | } |
bellard | 6420120 | 2004-05-26 22:55:16 +0000 | [diff] [blame] | 250 | |
Mark Cave-Ayland | 0662946 | 2018-05-03 21:24:39 +0100 | [diff] [blame] | 251 | /* UniN init */ |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 252 | dev = qdev_new(TYPE_UNI_NORTH); |
Mark Cave-Ayland | 0662946 | 2018-05-03 21:24:39 +0100 | [diff] [blame] | 253 | s = SYS_BUS_DEVICE(dev); |
Markus Armbruster | 3c6ef47 | 2020-06-10 07:32:34 +0200 | [diff] [blame] | 254 | sysbus_realize_and_unref(s, &error_fatal); |
Mark Cave-Ayland | 0662946 | 2018-05-03 21:24:39 +0100 | [diff] [blame] | 255 | memory_region_add_subregion(get_system_memory(), 0xf8000000, |
| 256 | sysbus_mmio_get_region(s, 0)); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 257 | |
Greg Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 258 | openpic_irqs = g_new0(IrqLines, smp_cpus); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 259 | 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 Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 265 | openpic_irqs[i].irq[OPENPIC_OUTPUT_INT] = |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 266 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]; |
Greg Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 267 | openpic_irqs[i].irq[OPENPIC_OUTPUT_CINT] = |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 268 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]; |
Greg Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 269 | openpic_irqs[i].irq[OPENPIC_OUTPUT_MCK] = |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 270 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_MCP]; |
| 271 | /* Not connected ? */ |
Greg Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 272 | openpic_irqs[i].irq[OPENPIC_OUTPUT_DEBUG] = NULL; |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 273 | /* Check this */ |
Greg Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 274 | openpic_irqs[i].irq[OPENPIC_OUTPUT_RESET] = |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 275 | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_HRESET]; |
| 276 | break; |
| 277 | #if defined(TARGET_PPC64) |
| 278 | case PPC_FLAGS_INPUT_970: |
Greg Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 279 | openpic_irqs[i].irq[OPENPIC_OUTPUT_INT] = |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 280 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT]; |
Greg Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 281 | openpic_irqs[i].irq[OPENPIC_OUTPUT_CINT] = |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 282 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT]; |
Greg Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 283 | openpic_irqs[i].irq[OPENPIC_OUTPUT_MCK] = |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 284 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_MCP]; |
| 285 | /* Not connected ? */ |
Greg Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 286 | openpic_irqs[i].irq[OPENPIC_OUTPUT_DEBUG] = NULL; |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 287 | /* Check this */ |
Greg Kurz | 9929301 | 2018-11-27 14:06:22 +0100 | [diff] [blame] | 288 | openpic_irqs[i].irq[OPENPIC_OUTPUT_RESET] = |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 289 | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_HRESET]; |
| 290 | break; |
| 291 | #endif /* defined(TARGET_PPC64) */ |
| 292 | default: |
Markus Armbruster | c525436 | 2015-12-17 17:35:09 +0100 | [diff] [blame] | 293 | error_report("Bus model not supported on mac99 machine"); |
j_mayer | dd37a5e | 2007-04-16 07:41:07 +0000 | [diff] [blame] | 294 | exit(1); |
| 295 | } |
bellard | 6420120 | 2004-05-26 22:55:16 +0000 | [diff] [blame] | 296 | } |
Alexander Graf | d0b7263 | 2012-12-08 05:17:14 +0100 | [diff] [blame] | 297 | |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 298 | if (PPC_INPUT(env) == PPC_FLAGS_INPUT_970) { |
| 299 | /* 970 gets a U3 bus */ |
Mark Cave-Ayland | 8ce3f74 | 2018-03-06 20:30:57 +0000 | [diff] [blame] | 300 | /* Uninorth AGP bus */ |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 301 | dev = qdev_new(TYPE_U3_AGP_HOST_BRIDGE); |
Markus Armbruster | 3c6ef47 | 2020-06-10 07:32:34 +0200 | [diff] [blame] | 302 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
Mark Cave-Ayland | 8ce3f74 | 2018-03-06 20:30:57 +0000 | [diff] [blame] | 303 | 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-Ayland | e226efb | 2018-03-06 20:30:59 +0000 | [diff] [blame] | 308 | /* 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-Ayland | 8ce3f74 | 2018-03-06 20:30:57 +0000 | [diff] [blame] | 311 | sysbus_mmio_map(s, 0, 0xf0800000); |
| 312 | sysbus_mmio_map(s, 1, 0xf0c00000); |
| 313 | |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 314 | machine_arch = ARCH_MAC99_U3; |
| 315 | } else { |
Mark Cave-Ayland | 7b19318 | 2018-03-06 20:30:56 +0000 | [diff] [blame] | 316 | /* Use values found on a real PowerMac */ |
| 317 | /* Uninorth AGP bus */ |
Mark Cave-Ayland | 6ce97b2 | 2020-12-29 17:56:16 +0000 | [diff] [blame] | 318 | uninorth_agp_dev = qdev_new(TYPE_UNI_NORTH_AGP_HOST_BRIDGE); |
| 319 | s = SYS_BUS_DEVICE(uninorth_agp_dev); |
Markus Armbruster | 3c6ef47 | 2020-06-10 07:32:34 +0200 | [diff] [blame] | 320 | sysbus_realize_and_unref(s, &error_fatal); |
Mark Cave-Ayland | 7b19318 | 2018-03-06 20:30:56 +0000 | [diff] [blame] | 321 | sysbus_mmio_map(s, 0, 0xf0800000); |
| 322 | sysbus_mmio_map(s, 1, 0xf0c00000); |
| 323 | |
| 324 | /* Uninorth internal bus */ |
Mark Cave-Ayland | 6ce97b2 | 2020-12-29 17:56:16 +0000 | [diff] [blame] | 325 | uninorth_internal_dev = qdev_new( |
| 326 | TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE); |
| 327 | s = SYS_BUS_DEVICE(uninorth_internal_dev); |
Markus Armbruster | 3c6ef47 | 2020-06-10 07:32:34 +0200 | [diff] [blame] | 328 | sysbus_realize_and_unref(s, &error_fatal); |
Mark Cave-Ayland | 7b19318 | 2018-03-06 20:30:56 +0000 | [diff] [blame] | 329 | sysbus_mmio_map(s, 0, 0xf4800000); |
| 330 | sysbus_mmio_map(s, 1, 0xf4c00000); |
| 331 | |
| 332 | /* Uninorth main bus */ |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 333 | dev = qdev_new(TYPE_UNI_NORTH_PCI_HOST_BRIDGE); |
Mark Cave-Ayland | 03756c8 | 2018-08-29 17:59:10 +0100 | [diff] [blame] | 334 | qdev_prop_set_uint32(dev, "ofw-addr", 0xf2000000); |
Markus Armbruster | 3c6ef47 | 2020-06-10 07:32:34 +0200 | [diff] [blame] | 335 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
Mark Cave-Ayland | 7b19318 | 2018-03-06 20:30:56 +0000 | [diff] [blame] | 336 | 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-Ayland | e226efb | 2018-03-06 20:30:59 +0000 | [diff] [blame] | 341 | /* 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-Ayland | 7b19318 | 2018-03-06 20:30:56 +0000 | [diff] [blame] | 344 | sysbus_mmio_map(s, 0, 0xf2800000); |
| 345 | sysbus_mmio_map(s, 1, 0xf2c00000); |
| 346 | |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 347 | machine_arch = ARCH_MAC99; |
| 348 | } |
Alexander Graf | caae6c9 | 2014-07-13 22:29:02 +0200 | [diff] [blame] | 349 | |
Alexander Graf | 72f1f97 | 2015-11-11 22:49:41 +0000 | [diff] [blame] | 350 | machine->usb |= defaults_enabled() && !machine->usb_disabled; |
Mark Cave-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 351 | 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 Graf | 72f1f97 | 2015-11-11 22:49:41 +0000 | [diff] [blame] | 354 | |
Alexander Graf | caae6c9 | 2014-07-13 22:29:02 +0200 | [diff] [blame] | 355 | /* Timebase Frequency */ |
| 356 | if (kvm_enabled()) { |
| 357 | tbfreq = kvmppc_get_tbfreq(); |
| 358 | } else { |
| 359 | tbfreq = TBFREQ; |
| 360 | } |
| 361 | |
Mark Cave-Ayland | 0f4b541 | 2018-03-06 20:30:50 +0000 | [diff] [blame] | 362 | /* init basic PC hardware */ |
| 363 | pci_bus = PCI_HOST_BRIDGE(uninorth_pci)->bus; |
| 364 | |
Mark Cave-Ayland | 343bd85 | 2018-02-28 20:32:33 +0000 | [diff] [blame] | 365 | /* MacIO */ |
Markus Armbruster | 9307d06 | 2020-06-10 07:32:04 +0200 | [diff] [blame] | 366 | macio = pci_new(-1, TYPE_NEWWORLD_MACIO); |
Andreas Färber | 07a7484 | 2013-01-23 23:04:01 +0000 | [diff] [blame] | 367 | dev = DEVICE(macio); |
Alexander Graf | b981289 | 2014-07-13 22:31:53 +0200 | [diff] [blame] | 368 | qdev_prop_set_uint64(dev, "frequency", tbfreq); |
Mark Cave-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 369 | qdev_prop_set_bit(dev, "has-pmu", has_pmu); |
| 370 | qdev_prop_set_bit(dev, "has-adb", has_adb); |
Mark Cave-Ayland | 348b8d1 | 2020-10-13 12:49:20 +0100 | [diff] [blame] | 371 | |
| 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 Armbruster | 9307d06 | 2020-06-10 07:32:04 +0200 | [diff] [blame] | 376 | pci_realize_and_unref(macio, pci_bus, &error_fatal); |
Andreas Färber | 07a7484 | 2013-01-23 23:04:01 +0000 | [diff] [blame] | 377 | |
Mark Cave-Ayland | 7e4d62d | 2020-12-29 17:56:17 +0000 | [diff] [blame] | 378 | pic_dev = DEVICE(object_resolve_path_component(OBJECT(macio), "pic")); |
Mark Cave-Ayland | 6ce97b2 | 2020-12-29 17:56:16 +0000 | [diff] [blame] | 379 | 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-Ayland | 7e4d62d | 2020-12-29 17:56:17 +0000 | [diff] [blame] | 399 | /* 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ärber | 07a7484 | 2013-01-23 23:04:01 +0000 | [diff] [blame] | 409 | /* We only emulate 2 out of 3 IDE controllers for now */ |
John Snow | d8f94e1 | 2014-10-01 14:19:27 -0400 | [diff] [blame] | 410 | ide_drive_get(hd, ARRAY_SIZE(hd)); |
BALATON Zoltan | a0bb2a5 | 2014-06-24 00:03:48 +0200 | [diff] [blame] | 411 | |
Andreas Färber | 07a7484 | 2013-01-23 23:04:01 +0000 | [diff] [blame] | 412 | 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]); |
pbrook | 0d92ed3 | 2006-05-21 16:30:15 +0000 | [diff] [blame] | 419 | |
Mark Cave-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 420 | if (has_adb) { |
Mark Cave-Ayland | d811d61 | 2018-06-12 17:44:02 +0100 | [diff] [blame] | 421 | 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-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 427 | adb_bus = qdev_get_child_bus(dev, "adb.0"); |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 428 | dev = qdev_new(TYPE_ADB_KEYBOARD); |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 429 | qdev_realize_and_unref(dev, adb_bus, &error_fatal); |
Mark Cave-Ayland | d811d61 | 2018-06-12 17:44:02 +0100 | [diff] [blame] | 430 | |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 431 | dev = qdev_new(TYPE_ADB_MOUSE); |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 432 | qdev_realize_and_unref(dev, adb_bus, &error_fatal); |
Mark Cave-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 433 | } |
Andreas Färber | 45fa67f | 2013-01-23 23:04:02 +0000 | [diff] [blame] | 434 | |
Marcel Apfelbaum | 59a0419 | 2015-01-06 15:29:17 +0200 | [diff] [blame] | 435 | if (machine->usb) { |
Gerd Hoffmann | afb9a60 | 2012-03-07 15:06:32 +0100 | [diff] [blame] | 436 | pci_create_simple(pci_bus, -1, "pci-ohci"); |
Markus Armbruster | c86580b | 2015-02-04 13:28:14 +0100 | [diff] [blame] | 437 | |
zhlcindy@gmail.com | 094b287 | 2012-09-02 19:25:28 +0000 | [diff] [blame] | 438 | /* U3 needs to use USB for input because Linux doesn't support via-cuda |
| 439 | on PPC64 */ |
Mark Cave-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 440 | if (!has_adb || machine_arch == ARCH_MAC99_U3) { |
Markus Armbruster | c86580b | 2015-02-04 13:28:14 +0100 | [diff] [blame] | 441 | 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.com | 094b287 | 2012-09-02 19:25:28 +0000 | [diff] [blame] | 445 | } |
Alexander Graf | a2236d4 | 2010-02-09 17:37:08 +0100 | [diff] [blame] | 446 | } |
| 447 | |
BALATON Zoltan | a0bb2a5 | 2014-06-24 00:03:48 +0200 | [diff] [blame] | 448 | pci_vga_init(pci_bus); |
| 449 | |
| 450 | if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) { |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 451 | graphic_depth = 15; |
BALATON Zoltan | a0bb2a5 | 2014-06-24 00:03:48 +0200 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | for (i = 0; i < nb_nics; i++) { |
Mark Cave-Ayland | 4479b51 | 2019-02-08 17:22:01 +0000 | [diff] [blame] | 455 | pci_nic_init_nofail(&nd_table[i], pci_bus, "sungem", NULL); |
BALATON Zoltan | a0bb2a5 | 2014-06-24 00:03:48 +0200 | [diff] [blame] | 456 | } |
blueswir1 | 4f3f238 | 2009-02-08 16:01:01 +0000 | [diff] [blame] | 457 | |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 458 | /* The NewWorld NVRAM is not located in the MacIO device */ |
Wei Yang | 038adc2 | 2019-10-13 10:11:45 +0800 | [diff] [blame] | 459 | if (kvm_enabled() && qemu_real_host_page_size > 4096) { |
Alexander Graf | 261265c | 2014-07-11 03:24:39 +0200 | [diff] [blame] | 460 | /* 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 Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 464 | dev = qdev_new(TYPE_MACIO_NVRAM); |
Andreas Färber | 95ed3b7 | 2013-01-23 23:04:00 +0000 | [diff] [blame] | 465 | qdev_prop_set_uint32(dev, "size", 0x2000); |
| 466 | qdev_prop_set_uint32(dev, "it_shift", 1); |
Markus Armbruster | 3c6ef47 | 2020-06-10 07:32:34 +0200 | [diff] [blame] | 467 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
Alexander Graf | 261265c | 2014-07-11 03:24:39 +0200 | [diff] [blame] | 468 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, nvram_addr); |
Andreas Färber | 95ed3b7 | 2013-01-23 23:04:00 +0000 | [diff] [blame] | 469 | nvr = MACIO_NVRAM(dev); |
j_mayer | 3cbee15 | 2007-10-28 23:42:18 +0000 | [diff] [blame] | 470 | pmac_format_nvram_partition(nvr, 0x2000); |
bellard | b6b8bd1 | 2004-06-21 16:55:53 +0000 | [diff] [blame] | 471 | /* No PCI init: the BIOS will do it */ |
bellard | 0aa6a4a | 2005-06-05 15:11:17 +0000 | [diff] [blame] | 472 | |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 473 | dev = qdev_new(TYPE_FW_CFG_MEM); |
Mark Cave-Ayland | 74887ed | 2018-08-10 11:27:57 +0100 | [diff] [blame] | 474 | 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 Armbruster | d262312 | 2020-05-05 17:29:22 +0200 | [diff] [blame] | 478 | OBJECT(fw_cfg)); |
Mark Cave-Ayland | 74887ed | 2018-08-10 11:27:57 +0100 | [diff] [blame] | 479 | s = SYS_BUS_DEVICE(dev); |
Markus Armbruster | 3c6ef47 | 2020-06-10 07:32:34 +0200 | [diff] [blame] | 480 | sysbus_realize_and_unref(s, &error_fatal); |
Mark Cave-Ayland | 74887ed | 2018-08-10 11:27:57 +0100 | [diff] [blame] | 481 | sysbus_mmio_map(s, 0, CFG_ADDR); |
| 482 | sysbus_mmio_map(s, 1, CFG_ADDR + 2); |
| 483 | |
Igor Mammedov | 5836d16 | 2016-11-15 13:17:15 +0100 | [diff] [blame] | 484 | fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)smp_cpus); |
Like Xu | fe6b634 | 2019-05-19 04:54:22 +0800 | [diff] [blame] | 485 | fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)machine->smp.max_cpus); |
blueswir1 | 006f3a4 | 2009-02-08 15:59:36 +0000 | [diff] [blame] | 486 | fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); |
Alexander Graf | 0f92119 | 2010-02-09 17:37:02 +0100 | [diff] [blame] | 487 | fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, machine_arch); |
blueswir1 | 513f789 | 2009-03-08 09:51:29 +0000 | [diff] [blame] | 488 | 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 Graf | b9e17a3 | 2011-06-15 23:27:19 +0200 | [diff] [blame] | 491 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base); |
| 492 | pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline); |
blueswir1 | 513f789 | 2009-03-08 09:51:29 +0000 | [diff] [blame] | 493 | } 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 Swirl | 10696b4 | 2009-08-08 10:47:15 +0000 | [diff] [blame] | 499 | |
| 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-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 504 | fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_VIACONFIG, core99_machine->via_config); |
| 505 | |
Alexander Graf | 45024f0 | 2010-08-03 15:22:42 +0200 | [diff] [blame] | 506 | fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled()); |
Alexander Graf | dc333cd | 2010-02-09 17:37:05 +0100 | [diff] [blame] | 507 | if (kvm_enabled()) { |
Alexander Graf | 45024f0 | 2010-08-03 15:22:42 +0200 | [diff] [blame] | 508 | uint8_t *hypercall; |
| 509 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 510 | hypercall = g_malloc(16); |
Alexander Graf | 45024f0 | 2010-08-03 15:22:42 +0200 | [diff] [blame] | 511 | 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 Graf | dc333cd | 2010-02-09 17:37:05 +0100 | [diff] [blame] | 514 | } |
Alexander Graf | caae6c9 | 2014-07-13 22:29:02 +0200 | [diff] [blame] | 515 | fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, tbfreq); |
Alexander Graf | a1014f2 | 2013-06-23 00:22:50 +0200 | [diff] [blame] | 516 | /* Mac OS X requires a "known good" clock-frequency value; pass it one. */ |
BALATON Zoltan | 9d1c128 | 2014-04-17 19:04:44 +0200 | [diff] [blame] | 517 | fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_CLOCKFREQ, CLOCKFREQ); |
| 518 | fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_BUSFREQ, BUSFREQ); |
Alexander Graf | 261265c | 2014-07-11 03:24:39 +0200 | [diff] [blame] | 519 | fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_NVRAM_ADDR, nvram_addr); |
Alexander Graf | dc333cd | 2010-02-09 17:37:05 +0100 | [diff] [blame] | 520 | |
Mark Cave-Ayland | 53ecf09 | 2017-05-01 14:43:33 +0100 | [diff] [blame] | 521 | /* MacOS NDRV VGA driver */ |
| 522 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, NDRV_VGA_FILENAME); |
| 523 | if (filename) { |
Peter Maydell | 9776874 | 2018-12-14 13:30:50 +0000 | [diff] [blame] | 524 | gchar *ndrv_file; |
| 525 | gsize ndrv_size; |
Mark Cave-Ayland | 53ecf09 | 2017-05-01 14:43:33 +0100 | [diff] [blame] | 526 | |
Peter Maydell | 9776874 | 2018-12-14 13:30:50 +0000 | [diff] [blame] | 527 | if (g_file_get_contents(filename, &ndrv_file, &ndrv_size, NULL)) { |
Mark Cave-Ayland | 53ecf09 | 2017-05-01 14:43:33 +0100 | [diff] [blame] | 528 | fw_cfg_add_file(fw_cfg, "ndrv/qemu_vga.ndrv", ndrv_file, ndrv_size); |
| 529 | } |
| 530 | g_free(filename); |
| 531 | } |
| 532 | |
blueswir1 | 513f789 | 2009-03-08 09:51:29 +0000 | [diff] [blame] | 533 | qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); |
j_mayer | aae9366 | 2007-11-24 02:56:36 +0000 | [diff] [blame] | 534 | } |
bellard | 0aa6a4a | 2005-06-05 15:11:17 +0000 | [diff] [blame] | 535 | |
Mark Cave-Ayland | 5d19be6 | 2018-08-29 17:59:11 +0100 | [diff] [blame] | 536 | /* |
| 537 | * Implementation of an interface to adjust firmware path |
| 538 | * for the bootindex property handling. |
| 539 | */ |
| 540 | static char *core99_fw_dev_path(FWPathProvider *p, BusState *bus, |
| 541 | DeviceState *dev) |
| 542 | { |
| 543 | PCIDevice *pci; |
Mark Cave-Ayland | 5d19be6 | 2018-08-29 17:59:11 +0100 | [diff] [blame] | 544 | 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-Ayland | 5d19be6 | 2018-08-29 17:59:11 +0100 | [diff] [blame] | 556 | if (!strcmp(object_get_typename(OBJECT(dev)), "ide-hd")) { |
Mark Cave-Ayland | 31bc6fa | 2019-03-07 21:20:58 +0000 | [diff] [blame] | 557 | return g_strdup("disk"); |
Mark Cave-Ayland | 5d19be6 | 2018-08-29 17:59:11 +0100 | [diff] [blame] | 558 | } |
| 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 Auger | dc0ca80 | 2019-03-04 11:13:33 +0100 | [diff] [blame] | 570 | static int core99_kvm_type(MachineState *machine, const char *arg) |
Alexander Graf | 277c7a4 | 2014-07-24 10:46:47 +0200 | [diff] [blame] | 571 | { |
| 572 | /* Always force PR KVM */ |
| 573 | return 2; |
| 574 | } |
| 575 | |
Marcel Apfelbaum | b1c2fb9 | 2015-01-06 15:29:15 +0200 | [diff] [blame] | 576 | static void core99_machine_class_init(ObjectClass *oc, void *data) |
Anthony Liguori | f80f9ec | 2009-05-20 18:38:09 -0500 | [diff] [blame] | 577 | { |
Marcel Apfelbaum | b1c2fb9 | 2015-01-06 15:29:15 +0200 | [diff] [blame] | 578 | MachineClass *mc = MACHINE_CLASS(oc); |
Mark Cave-Ayland | 5d19be6 | 2018-08-29 17:59:11 +0100 | [diff] [blame] | 579 | FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc); |
Marcel Apfelbaum | b1c2fb9 | 2015-01-06 15:29:15 +0200 | [diff] [blame] | 580 | |
Marcel Apfelbaum | b1c2fb9 | 2015-01-06 15:29:15 +0200 | [diff] [blame] | 581 | mc->desc = "Mac99 based PowerMAC"; |
| 582 | mc->init = ppc_core99_init; |
Markus Armbruster | 2059839 | 2017-02-15 11:05:40 +0100 | [diff] [blame] | 583 | mc->block_default_type = IF_IDE; |
Marcel Apfelbaum | b1c2fb9 | 2015-01-06 15:29:15 +0200 | [diff] [blame] | 584 | mc->max_cpus = MAX_CPUS; |
| 585 | mc->default_boot_order = "cd"; |
Mark Cave-Ayland | 3232794 | 2018-07-03 20:10:43 +0100 | [diff] [blame] | 586 | mc->default_display = "std"; |
Marcel Apfelbaum | b1c2fb9 | 2015-01-06 15:29:15 +0200 | [diff] [blame] | 587 | mc->kvm_type = core99_kvm_type; |
Igor Mammedov | 9dff4c0 | 2017-10-09 21:50:52 +0200 | [diff] [blame] | 588 | #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 Mammedov | a5b5de0 | 2020-02-19 11:09:34 -0500 | [diff] [blame] | 593 | mc->default_ram_id = "ppc_core99.ram"; |
Mark Cave-Ayland | 5d19be6 | 2018-08-29 17:59:11 +0100 | [diff] [blame] | 594 | mc->ignore_boot_device_suffixes = true; |
| 595 | fwc->get_dev_path = core99_fw_dev_path; |
Anthony Liguori | f80f9ec | 2009-05-20 18:38:09 -0500 | [diff] [blame] | 596 | } |
| 597 | |
Mark Cave-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 598 | static 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 | |
| 615 | static 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-Ayland | 06fe3a5 | 2018-06-12 17:43:56 +0100 | [diff] [blame] | 631 | static void core99_instance_init(Object *obj) |
| 632 | { |
Mark Cave-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 633 | 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 Armbruster | d262312 | 2020-05-05 17:29:22 +0200 | [diff] [blame] | 638 | core99_set_via_config); |
Mark Cave-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 639 | object_property_set_description(obj, "via", |
| 640 | "Set VIA configuration. " |
Markus Armbruster | 7eecec7 | 2020-05-05 17:29:15 +0200 | [diff] [blame] | 641 | "Valid values are cuda, pmu and pmu-adb"); |
Mark Cave-Ayland | f1114c1 | 2018-06-12 17:43:57 +0100 | [diff] [blame] | 642 | |
Mark Cave-Ayland | 06fe3a5 | 2018-06-12 17:43:56 +0100 | [diff] [blame] | 643 | return; |
| 644 | } |
| 645 | |
Marcel Apfelbaum | b1c2fb9 | 2015-01-06 15:29:15 +0200 | [diff] [blame] | 646 | static const TypeInfo core99_machine_info = { |
Eduardo Habkost | c0f3651 | 2015-08-20 14:54:34 -0700 | [diff] [blame] | 647 | .name = MACHINE_TYPE_NAME("mac99"), |
Marcel Apfelbaum | b1c2fb9 | 2015-01-06 15:29:15 +0200 | [diff] [blame] | 648 | .parent = TYPE_MACHINE, |
| 649 | .class_init = core99_machine_class_init, |
Mark Cave-Ayland | 06fe3a5 | 2018-06-12 17:43:56 +0100 | [diff] [blame] | 650 | .instance_init = core99_instance_init, |
Mark Cave-Ayland | 5d19be6 | 2018-08-29 17:59:11 +0100 | [diff] [blame] | 651 | .instance_size = sizeof(Core99MachineState), |
| 652 | .interfaces = (InterfaceInfo[]) { |
| 653 | { TYPE_FW_PATH_PROVIDER }, |
| 654 | { } |
| 655 | }, |
Marcel Apfelbaum | b1c2fb9 | 2015-01-06 15:29:15 +0200 | [diff] [blame] | 656 | }; |
| 657 | |
| 658 | static void mac_machine_register_types(void) |
| 659 | { |
| 660 | type_register_static(&core99_machine_info); |
| 661 | } |
| 662 | |
| 663 | type_init(mac_machine_register_types) |