j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU PowerPC 405 evaluation boards emulation |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 4 | * Copyright (c) 2007 Jocelyn Mayer |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5 | * |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
Peter Maydell | 0d75590 | 2016-01-26 18:16:58 +0000 | [diff] [blame] | 24 | #include "qemu/osdep.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 25 | #include "qapi/error.h" |
Paolo Bonzini | 4771d75 | 2016-01-19 21:51:44 +0100 | [diff] [blame] | 26 | #include "qemu-common.h" |
| 27 | #include "cpu.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 28 | #include "hw/hw.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 29 | #include "hw/ppc/ppc.h" |
Paolo Bonzini | 47b43a1 | 2013-03-18 17:36:02 +0100 | [diff] [blame] | 30 | #include "ppc405.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 31 | #include "hw/timer/m48t59.h" |
| 32 | #include "hw/block/flash.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 33 | #include "sysemu/sysemu.h" |
Andreas Färber | ad9990a | 2013-08-05 15:27:23 +0200 | [diff] [blame] | 34 | #include "sysemu/qtest.h" |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 35 | #include "sysemu/block-backend.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 36 | #include "hw/boards.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 37 | #include "qemu/log.h" |
Andreas Färber | ad9990a | 2013-08-05 15:27:23 +0200 | [diff] [blame] | 38 | #include "qemu/error-report.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 39 | #include "hw/loader.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 40 | #include "sysemu/blockdev.h" |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 41 | #include "exec/address-spaces.h" |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 42 | |
| 43 | #define BIOS_FILENAME "ppc405_rom.bin" |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 44 | #define BIOS_SIZE (2048 * 1024) |
| 45 | |
| 46 | #define KERNEL_LOAD_ADDR 0x00000000 |
| 47 | #define INITRD_LOAD_ADDR 0x01800000 |
| 48 | |
| 49 | #define USE_FLASH_BIOS |
| 50 | |
Andreas Färber | bf2ed91 | 2013-08-05 15:27:21 +0200 | [diff] [blame] | 51 | //#define DEBUG_BOARD_INIT |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 52 | |
| 53 | /*****************************************************************************/ |
| 54 | /* PPC405EP reference board (IBM) */ |
| 55 | /* Standalone board with: |
| 56 | * - PowerPC 405EP CPU |
| 57 | * - SDRAM (0x00000000) |
| 58 | * - Flash (0xFFF80000) |
| 59 | * - SRAM (0xFFF00000) |
| 60 | * - NVRAM (0xF0000000) |
| 61 | * - FPGA (0xF0300000) |
| 62 | */ |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 63 | typedef struct ref405ep_fpga_t ref405ep_fpga_t; |
| 64 | struct ref405ep_fpga_t { |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 65 | uint8_t reg0; |
| 66 | uint8_t reg1; |
| 67 | }; |
| 68 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 69 | static uint32_t ref405ep_fpga_readb (void *opaque, hwaddr addr) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 70 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 71 | ref405ep_fpga_t *fpga; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 72 | uint32_t ret; |
| 73 | |
| 74 | fpga = opaque; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 75 | switch (addr) { |
| 76 | case 0x0: |
| 77 | ret = fpga->reg0; |
| 78 | break; |
| 79 | case 0x1: |
| 80 | ret = fpga->reg1; |
| 81 | break; |
| 82 | default: |
| 83 | ret = 0; |
| 84 | break; |
| 85 | } |
| 86 | |
| 87 | return ret; |
| 88 | } |
| 89 | |
| 90 | static void ref405ep_fpga_writeb (void *opaque, |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 91 | hwaddr addr, uint32_t value) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 92 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 93 | ref405ep_fpga_t *fpga; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 94 | |
| 95 | fpga = opaque; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 96 | switch (addr) { |
| 97 | case 0x0: |
| 98 | /* Read only */ |
| 99 | break; |
| 100 | case 0x1: |
| 101 | fpga->reg1 = value; |
| 102 | break; |
| 103 | default: |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 108 | static uint32_t ref405ep_fpga_readw (void *opaque, hwaddr addr) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 109 | { |
| 110 | uint32_t ret; |
| 111 | |
| 112 | ret = ref405ep_fpga_readb(opaque, addr) << 8; |
| 113 | ret |= ref405ep_fpga_readb(opaque, addr + 1); |
| 114 | |
| 115 | return ret; |
| 116 | } |
| 117 | |
| 118 | static void ref405ep_fpga_writew (void *opaque, |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 119 | hwaddr addr, uint32_t value) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 120 | { |
| 121 | ref405ep_fpga_writeb(opaque, addr, (value >> 8) & 0xFF); |
| 122 | ref405ep_fpga_writeb(opaque, addr + 1, value & 0xFF); |
| 123 | } |
| 124 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 125 | static uint32_t ref405ep_fpga_readl (void *opaque, hwaddr addr) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 126 | { |
| 127 | uint32_t ret; |
| 128 | |
| 129 | ret = ref405ep_fpga_readb(opaque, addr) << 24; |
| 130 | ret |= ref405ep_fpga_readb(opaque, addr + 1) << 16; |
| 131 | ret |= ref405ep_fpga_readb(opaque, addr + 2) << 8; |
| 132 | ret |= ref405ep_fpga_readb(opaque, addr + 3); |
| 133 | |
| 134 | return ret; |
| 135 | } |
| 136 | |
| 137 | static void ref405ep_fpga_writel (void *opaque, |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 138 | hwaddr addr, uint32_t value) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 139 | { |
aurel32 | 8de2410 | 2008-12-11 22:43:07 +0000 | [diff] [blame] | 140 | ref405ep_fpga_writeb(opaque, addr, (value >> 24) & 0xFF); |
| 141 | ref405ep_fpga_writeb(opaque, addr + 1, (value >> 16) & 0xFF); |
| 142 | ref405ep_fpga_writeb(opaque, addr + 2, (value >> 8) & 0xFF); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 143 | ref405ep_fpga_writeb(opaque, addr + 3, value & 0xFF); |
| 144 | } |
| 145 | |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 146 | static const MemoryRegionOps ref405ep_fpga_ops = { |
| 147 | .old_mmio = { |
| 148 | .read = { |
| 149 | ref405ep_fpga_readb, ref405ep_fpga_readw, ref405ep_fpga_readl, |
| 150 | }, |
| 151 | .write = { |
| 152 | ref405ep_fpga_writeb, ref405ep_fpga_writew, ref405ep_fpga_writel, |
| 153 | }, |
| 154 | }, |
| 155 | .endianness = DEVICE_NATIVE_ENDIAN, |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | static void ref405ep_fpga_reset (void *opaque) |
| 159 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 160 | ref405ep_fpga_t *fpga; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 161 | |
| 162 | fpga = opaque; |
| 163 | fpga->reg0 = 0x00; |
| 164 | fpga->reg1 = 0x0F; |
| 165 | } |
| 166 | |
Eduardo Habkost | 5f072e1 | 2012-10-15 17:22:02 -0300 | [diff] [blame] | 167 | static void ref405ep_fpga_init(MemoryRegion *sysmem, uint32_t base) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 168 | { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 169 | ref405ep_fpga_t *fpga; |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 170 | MemoryRegion *fpga_memory = g_new(MemoryRegion, 1); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 171 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 172 | fpga = g_malloc0(sizeof(ref405ep_fpga_t)); |
Paolo Bonzini | 2c9b15c | 2013-06-06 05:41:28 -0400 | [diff] [blame] | 173 | memory_region_init_io(fpga_memory, NULL, &ref405ep_fpga_ops, fpga, |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 174 | "fpga", 0x00000100); |
| 175 | memory_region_add_subregion(sysmem, base, fpga_memory); |
Jan Kiszka | a08d436 | 2009-06-27 09:25:07 +0200 | [diff] [blame] | 176 | qemu_register_reset(&ref405ep_fpga_reset, fpga); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 179 | static void ref405ep_init(MachineState *machine) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 180 | { |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 181 | ram_addr_t ram_size = machine->ram_size; |
| 182 | const char *kernel_filename = machine->kernel_filename; |
| 183 | const char *kernel_cmdline = machine->kernel_cmdline; |
| 184 | const char *initrd_filename = machine->initrd_filename; |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 185 | char *filename; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 186 | ppc4xx_bd_info_t bd; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 187 | CPUPPCState *env; |
| 188 | qemu_irq *pic; |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 189 | MemoryRegion *bios; |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 190 | MemoryRegion *sram = g_new(MemoryRegion, 1); |
| 191 | ram_addr_t bdloc; |
Avi Kivity | b6dcbe0 | 2011-08-15 17:17:27 +0300 | [diff] [blame] | 192 | MemoryRegion *ram_memories = g_malloc(2 * sizeof(*ram_memories)); |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 193 | hwaddr ram_bases[2], ram_sizes[2]; |
Blue Swirl | 093209c | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 194 | target_ulong sram_size; |
| 195 | long bios_size; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 196 | //int phy_addr = 0; |
| 197 | //static int phy_addr = 1; |
Blue Swirl | 093209c | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 198 | target_ulong kernel_base, initrd_base; |
| 199 | long kernel_size, initrd_size; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 200 | int linux_boot; |
| 201 | int fl_idx, fl_sectors, len; |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 202 | DriveInfo *dinfo; |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 203 | MemoryRegion *sysmem = get_system_memory(); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 204 | |
thuth@redhat.com | 64b4745 | 2018-01-21 22:57:58 +0100 | [diff] [blame] | 205 | #ifdef TARGET_PPCEMB |
| 206 | if (!qtest_enabled()) { |
| 207 | warn_report("qemu-system-ppcemb is deprecated, " |
| 208 | "please use qemu-system-ppc instead."); |
| 209 | } |
| 210 | #endif |
| 211 | |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 212 | /* XXX: fix this */ |
Shreyas B. Prabhu | e938ba0 | 2014-07-10 17:31:03 +0530 | [diff] [blame] | 213 | memory_region_allocate_system_memory(&ram_memories[0], NULL, "ef405ep.ram", |
| 214 | 0x08000000); |
Avi Kivity | b6dcbe0 | 2011-08-15 17:17:27 +0300 | [diff] [blame] | 215 | ram_bases[0] = 0; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 216 | ram_sizes[0] = 0x08000000; |
Paolo Bonzini | 2c9b15c | 2013-06-06 05:41:28 -0400 | [diff] [blame] | 217 | memory_region_init(&ram_memories[1], NULL, "ef405ep.ram1", 0); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 218 | ram_bases[1] = 0x00000000; |
| 219 | ram_sizes[1] = 0x00000000; |
| 220 | ram_size = 128 * 1024 * 1024; |
| 221 | #ifdef DEBUG_BOARD_INIT |
| 222 | printf("%s: register cpu\n", __func__); |
| 223 | #endif |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 224 | env = ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes, |
Richard Henderson | 52ce55a | 2011-08-11 16:07:17 -0700 | [diff] [blame] | 225 | 33333333, &pic, kernel_filename == NULL ? 0 : 1); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 226 | /* allocate SRAM */ |
pbrook | 5c130f6 | 2009-04-10 14:29:45 +0000 | [diff] [blame] | 227 | sram_size = 512 * 1024; |
Peter Maydell | 98a99ce | 2017-07-07 15:42:53 +0100 | [diff] [blame] | 228 | memory_region_init_ram(sram, NULL, "ef405ep.sram", sram_size, |
Markus Armbruster | f8ed85a | 2015-09-11 16:51:43 +0200 | [diff] [blame] | 229 | &error_fatal); |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 230 | memory_region_add_subregion(sysmem, 0xFFF00000, sram); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 231 | /* allocate and load BIOS */ |
| 232 | #ifdef DEBUG_BOARD_INIT |
| 233 | printf("%s: register BIOS\n", __func__); |
| 234 | #endif |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 235 | fl_idx = 0; |
| 236 | #ifdef USE_FLASH_BIOS |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 237 | dinfo = drive_get(IF_PFLASH, 0, fl_idx); |
| 238 | if (dinfo) { |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 239 | BlockBackend *blk = blk_by_legacy_dinfo(dinfo); |
Markus Armbruster | fa1d36d | 2014-10-07 13:59:13 +0200 | [diff] [blame] | 240 | |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 241 | bios_size = blk_getlength(blk); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 242 | fl_sectors = (bios_size + 65535) >> 16; |
| 243 | #ifdef DEBUG_BOARD_INIT |
Blue Swirl | 093209c | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 244 | printf("Register parallel flash %d size %lx" |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 245 | " at addr %lx '%s' %d\n", |
| 246 | fl_idx, bios_size, -bios_size, |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 247 | blk_name(blk), fl_sectors); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 248 | #endif |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 249 | pflash_cfi02_register((uint32_t)(-bios_size), |
| 250 | NULL, "ef405ep.bios", bios_size, |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 251 | blk, 65536, fl_sectors, 1, |
Anthony Liguori | 01e0451 | 2011-08-25 14:39:18 -0500 | [diff] [blame] | 252 | 2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA, |
| 253 | 1); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 254 | fl_idx++; |
| 255 | } else |
| 256 | #endif |
| 257 | { |
| 258 | #ifdef DEBUG_BOARD_INIT |
| 259 | printf("Load BIOS from file\n"); |
| 260 | #endif |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 261 | bios = g_new(MemoryRegion, 1); |
Peter Maydell | 98a99ce | 2017-07-07 15:42:53 +0100 | [diff] [blame] | 262 | memory_region_init_ram(bios, NULL, "ef405ep.bios", BIOS_SIZE, |
Markus Armbruster | f8ed85a | 2015-09-11 16:51:43 +0200 | [diff] [blame] | 263 | &error_fatal); |
Hu Tao | e206ad4 | 2014-07-21 17:30:17 +0800 | [diff] [blame] | 264 | |
j_mayer | 1192dad | 2007-10-05 13:08:35 +0000 | [diff] [blame] | 265 | if (bios_name == NULL) |
| 266 | bios_name = BIOS_FILENAME; |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 267 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); |
| 268 | if (filename) { |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 269 | bios_size = load_image(filename, memory_region_get_ram_ptr(bios)); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 270 | g_free(filename); |
Andreas Färber | ad9990a | 2013-08-05 15:27:23 +0200 | [diff] [blame] | 271 | if (bios_size < 0 || bios_size > BIOS_SIZE) { |
| 272 | error_report("Could not load PowerPC BIOS '%s'", bios_name); |
| 273 | exit(1); |
| 274 | } |
| 275 | bios_size = (bios_size + 0xfff) & ~0xfff; |
| 276 | memory_region_add_subregion(sysmem, (uint32_t)(-bios_size), bios); |
| 277 | } else if (!qtest_enabled() || kernel_filename != NULL) { |
| 278 | error_report("Could not load PowerPC BIOS '%s'", bios_name); |
| 279 | exit(1); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 280 | } else { |
Andreas Färber | ad9990a | 2013-08-05 15:27:23 +0200 | [diff] [blame] | 281 | /* Avoid an uninitialized variable warning */ |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 282 | bios_size = -1; |
| 283 | } |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 284 | memory_region_set_readonly(bios, true); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 285 | } |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 286 | /* Register FPGA */ |
| 287 | #ifdef DEBUG_BOARD_INIT |
| 288 | printf("%s: register FPGA\n", __func__); |
| 289 | #endif |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 290 | ref405ep_fpga_init(sysmem, 0xF0300000); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 291 | /* Register NVRAM */ |
| 292 | #ifdef DEBUG_BOARD_INIT |
| 293 | printf("%s: register NVRAM\n", __func__); |
| 294 | #endif |
Mark Cave-Ayland | 6de0497 | 2015-03-02 22:23:27 +0000 | [diff] [blame] | 295 | m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 296 | /* Load kernel */ |
| 297 | linux_boot = (kernel_filename != NULL); |
| 298 | if (linux_boot) { |
| 299 | #ifdef DEBUG_BOARD_INIT |
| 300 | printf("%s: load kernel\n", __func__); |
| 301 | #endif |
| 302 | memset(&bd, 0, sizeof(bd)); |
| 303 | bd.bi_memstart = 0x00000000; |
| 304 | bd.bi_memsize = ram_size; |
j_mayer | 217fae2 | 2007-10-03 01:04:20 +0000 | [diff] [blame] | 305 | bd.bi_flashstart = -bios_size; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 306 | bd.bi_flashsize = -bios_size; |
| 307 | bd.bi_flashoffset = 0; |
| 308 | bd.bi_sramstart = 0xFFF00000; |
| 309 | bd.bi_sramsize = sram_size; |
| 310 | bd.bi_bootflags = 0; |
| 311 | bd.bi_intfreq = 133333333; |
| 312 | bd.bi_busfreq = 33333333; |
| 313 | bd.bi_baudrate = 115200; |
| 314 | bd.bi_s_version[0] = 'Q'; |
| 315 | bd.bi_s_version[1] = 'M'; |
| 316 | bd.bi_s_version[2] = 'U'; |
| 317 | bd.bi_s_version[3] = '\0'; |
| 318 | bd.bi_r_version[0] = 'Q'; |
| 319 | bd.bi_r_version[1] = 'E'; |
| 320 | bd.bi_r_version[2] = 'M'; |
| 321 | bd.bi_r_version[3] = 'U'; |
| 322 | bd.bi_r_version[4] = '\0'; |
| 323 | bd.bi_procfreq = 133333333; |
| 324 | bd.bi_plb_busfreq = 33333333; |
| 325 | bd.bi_pci_busfreq = 33333333; |
| 326 | bd.bi_opbfreq = 33333333; |
j_mayer | b8d3f5d | 2007-09-26 23:55:31 +0000 | [diff] [blame] | 327 | bdloc = ppc405_set_bootinfo(env, &bd, 0x00000001); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 328 | env->gpr[3] = bdloc; |
| 329 | kernel_base = KERNEL_LOAD_ADDR; |
| 330 | /* now we can load the kernel */ |
pbrook | 5c130f6 | 2009-04-10 14:29:45 +0000 | [diff] [blame] | 331 | kernel_size = load_image_targphys(kernel_filename, kernel_base, |
| 332 | ram_size - kernel_base); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 333 | if (kernel_size < 0) { |
Alistair Francis | 6f76b81 | 2018-02-03 09:43:10 +0100 | [diff] [blame] | 334 | error_report("could not load kernel '%s'", kernel_filename); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 335 | exit(1); |
| 336 | } |
Blue Swirl | 093209c | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 337 | printf("Load kernel size %ld at " TARGET_FMT_lx, |
pbrook | 5c130f6 | 2009-04-10 14:29:45 +0000 | [diff] [blame] | 338 | kernel_size, kernel_base); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 339 | /* load initrd */ |
| 340 | if (initrd_filename) { |
| 341 | initrd_base = INITRD_LOAD_ADDR; |
pbrook | 5c130f6 | 2009-04-10 14:29:45 +0000 | [diff] [blame] | 342 | initrd_size = load_image_targphys(initrd_filename, initrd_base, |
| 343 | ram_size - initrd_base); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 344 | if (initrd_size < 0) { |
Alistair Francis | 6f76b81 | 2018-02-03 09:43:10 +0100 | [diff] [blame] | 345 | error_report("could not load initial ram disk '%s'", |
| 346 | initrd_filename); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 347 | exit(1); |
| 348 | } |
| 349 | } else { |
| 350 | initrd_base = 0; |
| 351 | initrd_size = 0; |
| 352 | } |
| 353 | env->gpr[4] = initrd_base; |
| 354 | env->gpr[5] = initrd_size; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 355 | if (kernel_cmdline != NULL) { |
| 356 | len = strlen(kernel_cmdline); |
| 357 | bdloc -= ((len + 255) & ~255); |
Stefan Weil | e1fe50d | 2013-04-12 20:53:58 +0200 | [diff] [blame] | 358 | cpu_physical_memory_write(bdloc, kernel_cmdline, len + 1); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 359 | env->gpr[6] = bdloc; |
| 360 | env->gpr[7] = bdloc + len; |
| 361 | } else { |
| 362 | env->gpr[6] = 0; |
| 363 | env->gpr[7] = 0; |
| 364 | } |
| 365 | env->nip = KERNEL_LOAD_ADDR; |
| 366 | } else { |
| 367 | kernel_base = 0; |
| 368 | kernel_size = 0; |
| 369 | initrd_base = 0; |
| 370 | initrd_size = 0; |
| 371 | bdloc = 0; |
| 372 | } |
| 373 | #ifdef DEBUG_BOARD_INIT |
Andreas Färber | bf2ed91 | 2013-08-05 15:27:21 +0200 | [diff] [blame] | 374 | printf("bdloc " RAM_ADDR_FMT "\n", bdloc); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 375 | printf("%s: Done\n", __func__); |
| 376 | #endif |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Andreas Färber | 8a661ae | 2015-09-19 10:49:44 +0200 | [diff] [blame] | 379 | static void ref405ep_class_init(ObjectClass *oc, void *data) |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 380 | { |
Andreas Färber | 8a661ae | 2015-09-19 10:49:44 +0200 | [diff] [blame] | 381 | MachineClass *mc = MACHINE_CLASS(oc); |
| 382 | |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 383 | mc->desc = "ref405ep"; |
| 384 | mc->init = ref405ep_init; |
| 385 | } |
| 386 | |
Andreas Färber | 8a661ae | 2015-09-19 10:49:44 +0200 | [diff] [blame] | 387 | static const TypeInfo ref405ep_type = { |
| 388 | .name = MACHINE_TYPE_NAME("ref405ep"), |
| 389 | .parent = TYPE_MACHINE, |
| 390 | .class_init = ref405ep_class_init, |
| 391 | }; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 392 | |
| 393 | /*****************************************************************************/ |
| 394 | /* AMCC Taihu evaluation board */ |
| 395 | /* - PowerPC 405EP processor |
| 396 | * - SDRAM 128 MB at 0x00000000 |
| 397 | * - Boot flash 2 MB at 0xFFE00000 |
| 398 | * - Application flash 32 MB at 0xFC000000 |
| 399 | * - 2 serial ports |
| 400 | * - 2 ethernet PHY |
| 401 | * - 1 USB 1.1 device 0x50000000 |
| 402 | * - 1 LCD display 0x50100000 |
| 403 | * - 1 CPLD 0x50100000 |
| 404 | * - 1 I2C EEPROM |
| 405 | * - 1 I2C thermal sensor |
| 406 | * - a set of LEDs |
| 407 | * - bit-bang SPI port using GPIOs |
| 408 | * - 1 EBC interface connector 0 0x50200000 |
| 409 | * - 1 cardbus controller + expansion slot. |
| 410 | * - 1 PCI expansion slot. |
| 411 | */ |
| 412 | typedef struct taihu_cpld_t taihu_cpld_t; |
| 413 | struct taihu_cpld_t { |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 414 | uint8_t reg0; |
| 415 | uint8_t reg1; |
| 416 | }; |
| 417 | |
Peter Maydell | e2a176d | 2015-11-16 14:57:50 +0000 | [diff] [blame] | 418 | static uint64_t taihu_cpld_read(void *opaque, hwaddr addr, unsigned size) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 419 | { |
| 420 | taihu_cpld_t *cpld; |
| 421 | uint32_t ret; |
| 422 | |
| 423 | cpld = opaque; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 424 | switch (addr) { |
| 425 | case 0x0: |
| 426 | ret = cpld->reg0; |
| 427 | break; |
| 428 | case 0x1: |
| 429 | ret = cpld->reg1; |
| 430 | break; |
| 431 | default: |
| 432 | ret = 0; |
| 433 | break; |
| 434 | } |
| 435 | |
| 436 | return ret; |
| 437 | } |
| 438 | |
Peter Maydell | e2a176d | 2015-11-16 14:57:50 +0000 | [diff] [blame] | 439 | static void taihu_cpld_write(void *opaque, hwaddr addr, |
| 440 | uint64_t value, unsigned size) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 441 | { |
| 442 | taihu_cpld_t *cpld; |
| 443 | |
| 444 | cpld = opaque; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 445 | switch (addr) { |
| 446 | case 0x0: |
| 447 | /* Read only */ |
| 448 | break; |
| 449 | case 0x1: |
| 450 | cpld->reg1 = value; |
| 451 | break; |
| 452 | default: |
| 453 | break; |
| 454 | } |
| 455 | } |
| 456 | |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 457 | static const MemoryRegionOps taihu_cpld_ops = { |
Peter Maydell | e2a176d | 2015-11-16 14:57:50 +0000 | [diff] [blame] | 458 | .read = taihu_cpld_read, |
| 459 | .write = taihu_cpld_write, |
| 460 | .impl = { |
| 461 | .min_access_size = 1, |
| 462 | .max_access_size = 1, |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 463 | }, |
| 464 | .endianness = DEVICE_NATIVE_ENDIAN, |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 465 | }; |
| 466 | |
| 467 | static void taihu_cpld_reset (void *opaque) |
| 468 | { |
| 469 | taihu_cpld_t *cpld; |
| 470 | |
| 471 | cpld = opaque; |
| 472 | cpld->reg0 = 0x01; |
| 473 | cpld->reg1 = 0x80; |
| 474 | } |
| 475 | |
Eduardo Habkost | 5f072e1 | 2012-10-15 17:22:02 -0300 | [diff] [blame] | 476 | static void taihu_cpld_init(MemoryRegion *sysmem, uint32_t base) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 477 | { |
| 478 | taihu_cpld_t *cpld; |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 479 | MemoryRegion *cpld_memory = g_new(MemoryRegion, 1); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 480 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 481 | cpld = g_malloc0(sizeof(taihu_cpld_t)); |
Paolo Bonzini | 2c9b15c | 2013-06-06 05:41:28 -0400 | [diff] [blame] | 482 | memory_region_init_io(cpld_memory, NULL, &taihu_cpld_ops, cpld, "cpld", 0x100); |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 483 | memory_region_add_subregion(sysmem, base, cpld_memory); |
Jan Kiszka | a08d436 | 2009-06-27 09:25:07 +0200 | [diff] [blame] | 484 | qemu_register_reset(&taihu_cpld_reset, cpld); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 487 | static void taihu_405ep_init(MachineState *machine) |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 488 | { |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 489 | ram_addr_t ram_size = machine->ram_size; |
| 490 | const char *kernel_filename = machine->kernel_filename; |
| 491 | const char *initrd_filename = machine->initrd_filename; |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 492 | char *filename; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 493 | qemu_irq *pic; |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 494 | MemoryRegion *sysmem = get_system_memory(); |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 495 | MemoryRegion *bios; |
Avi Kivity | b6dcbe0 | 2011-08-15 17:17:27 +0300 | [diff] [blame] | 496 | MemoryRegion *ram_memories = g_malloc(2 * sizeof(*ram_memories)); |
Hu Tao | e206ad4 | 2014-07-21 17:30:17 +0800 | [diff] [blame] | 497 | MemoryRegion *ram = g_malloc0(sizeof(*ram)); |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 498 | hwaddr ram_bases[2], ram_sizes[2]; |
Blue Swirl | 093209c | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 499 | long bios_size; |
| 500 | target_ulong kernel_base, initrd_base; |
| 501 | long kernel_size, initrd_size; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 502 | int linux_boot; |
| 503 | int fl_idx, fl_sectors; |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 504 | DriveInfo *dinfo; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 505 | |
thuth@redhat.com | 64b4745 | 2018-01-21 22:57:58 +0100 | [diff] [blame] | 506 | #ifdef TARGET_PPCEMB |
| 507 | if (!qtest_enabled()) { |
| 508 | warn_report("qemu-system-ppcemb is deprecated, " |
| 509 | "please use qemu-system-ppc instead."); |
| 510 | } |
| 511 | #endif |
| 512 | |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 513 | /* RAM is soldered to the board so the size cannot be changed */ |
Hu Tao | e206ad4 | 2014-07-21 17:30:17 +0800 | [diff] [blame] | 514 | ram_size = 0x08000000; |
| 515 | memory_region_allocate_system_memory(ram, NULL, "taihu_405ep.ram", |
| 516 | ram_size); |
| 517 | |
Avi Kivity | b6dcbe0 | 2011-08-15 17:17:27 +0300 | [diff] [blame] | 518 | ram_bases[0] = 0; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 519 | ram_sizes[0] = 0x04000000; |
Hu Tao | e206ad4 | 2014-07-21 17:30:17 +0800 | [diff] [blame] | 520 | memory_region_init_alias(&ram_memories[0], NULL, |
| 521 | "taihu_405ep.ram-0", ram, ram_bases[0], |
| 522 | ram_sizes[0]); |
Avi Kivity | b6dcbe0 | 2011-08-15 17:17:27 +0300 | [diff] [blame] | 523 | ram_bases[1] = 0x04000000; |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 524 | ram_sizes[1] = 0x04000000; |
Hu Tao | e206ad4 | 2014-07-21 17:30:17 +0800 | [diff] [blame] | 525 | memory_region_init_alias(&ram_memories[1], NULL, |
| 526 | "taihu_405ep.ram-1", ram, ram_bases[1], |
| 527 | ram_sizes[1]); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 528 | #ifdef DEBUG_BOARD_INIT |
| 529 | printf("%s: register cpu\n", __func__); |
| 530 | #endif |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 531 | ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes, |
Richard Henderson | 52ce55a | 2011-08-11 16:07:17 -0700 | [diff] [blame] | 532 | 33333333, &pic, kernel_filename == NULL ? 0 : 1); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 533 | /* allocate and load BIOS */ |
| 534 | #ifdef DEBUG_BOARD_INIT |
| 535 | printf("%s: register BIOS\n", __func__); |
| 536 | #endif |
| 537 | fl_idx = 0; |
| 538 | #if defined(USE_FLASH_BIOS) |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 539 | dinfo = drive_get(IF_PFLASH, 0, fl_idx); |
| 540 | if (dinfo) { |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 541 | BlockBackend *blk = blk_by_legacy_dinfo(dinfo); |
Markus Armbruster | fa1d36d | 2014-10-07 13:59:13 +0200 | [diff] [blame] | 542 | |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 543 | bios_size = blk_getlength(blk); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 544 | /* XXX: should check that size is 2MB */ |
| 545 | // bios_size = 2 * 1024 * 1024; |
| 546 | fl_sectors = (bios_size + 65535) >> 16; |
| 547 | #ifdef DEBUG_BOARD_INIT |
Blue Swirl | 093209c | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 548 | printf("Register parallel flash %d size %lx" |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 549 | " at addr %lx '%s' %d\n", |
| 550 | fl_idx, bios_size, -bios_size, |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 551 | blk_name(blk), fl_sectors); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 552 | #endif |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 553 | pflash_cfi02_register((uint32_t)(-bios_size), |
| 554 | NULL, "taihu_405ep.bios", bios_size, |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 555 | blk, 65536, fl_sectors, 1, |
Anthony Liguori | 01e0451 | 2011-08-25 14:39:18 -0500 | [diff] [blame] | 556 | 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA, |
| 557 | 1); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 558 | fl_idx++; |
| 559 | } else |
| 560 | #endif |
| 561 | { |
| 562 | #ifdef DEBUG_BOARD_INIT |
| 563 | printf("Load BIOS from file\n"); |
| 564 | #endif |
j_mayer | 1192dad | 2007-10-05 13:08:35 +0000 | [diff] [blame] | 565 | if (bios_name == NULL) |
| 566 | bios_name = BIOS_FILENAME; |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 567 | bios = g_new(MemoryRegion, 1); |
Peter Maydell | 98a99ce | 2017-07-07 15:42:53 +0100 | [diff] [blame] | 568 | memory_region_init_ram(bios, NULL, "taihu_405ep.bios", BIOS_SIZE, |
Markus Armbruster | f8ed85a | 2015-09-11 16:51:43 +0200 | [diff] [blame] | 569 | &error_fatal); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 570 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); |
| 571 | if (filename) { |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 572 | bios_size = load_image(filename, memory_region_get_ram_ptr(bios)); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 573 | g_free(filename); |
Andreas Färber | ad9990a | 2013-08-05 15:27:23 +0200 | [diff] [blame] | 574 | if (bios_size < 0 || bios_size > BIOS_SIZE) { |
| 575 | error_report("Could not load PowerPC BIOS '%s'", bios_name); |
| 576 | exit(1); |
| 577 | } |
| 578 | bios_size = (bios_size + 0xfff) & ~0xfff; |
| 579 | memory_region_add_subregion(sysmem, (uint32_t)(-bios_size), bios); |
| 580 | } else if (!qtest_enabled()) { |
| 581 | error_report("Could not load PowerPC BIOS '%s'", bios_name); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 582 | exit(1); |
| 583 | } |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 584 | memory_region_set_readonly(bios, true); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 585 | } |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 586 | /* Register Linux flash */ |
Gerd Hoffmann | 751c6a1 | 2009-07-22 16:42:57 +0200 | [diff] [blame] | 587 | dinfo = drive_get(IF_PFLASH, 0, fl_idx); |
| 588 | if (dinfo) { |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 589 | BlockBackend *blk = blk_by_legacy_dinfo(dinfo); |
Markus Armbruster | fa1d36d | 2014-10-07 13:59:13 +0200 | [diff] [blame] | 590 | |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 591 | bios_size = blk_getlength(blk); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 592 | /* XXX: should check that size is 32MB */ |
| 593 | bios_size = 32 * 1024 * 1024; |
| 594 | fl_sectors = (bios_size + 65535) >> 16; |
| 595 | #ifdef DEBUG_BOARD_INIT |
Blue Swirl | 093209c | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 596 | printf("Register parallel flash %d size %lx" |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 597 | " at addr " TARGET_FMT_lx " '%s'\n", |
| 598 | fl_idx, bios_size, (target_ulong)0xfc000000, |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 599 | blk_name(blk)); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 600 | #endif |
Avi Kivity | cfe5f01 | 2011-08-04 15:55:30 +0300 | [diff] [blame] | 601 | pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size, |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 602 | blk, 65536, fl_sectors, 1, |
Anthony Liguori | 01e0451 | 2011-08-25 14:39:18 -0500 | [diff] [blame] | 603 | 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA, |
| 604 | 1); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 605 | fl_idx++; |
| 606 | } |
| 607 | /* Register CLPD & LCD display */ |
| 608 | #ifdef DEBUG_BOARD_INIT |
| 609 | printf("%s: register CPLD\n", __func__); |
| 610 | #endif |
Avi Kivity | a682fd5 | 2011-09-12 16:43:53 +0300 | [diff] [blame] | 611 | taihu_cpld_init(sysmem, 0x50100000); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 612 | /* Load kernel */ |
| 613 | linux_boot = (kernel_filename != NULL); |
| 614 | if (linux_boot) { |
| 615 | #ifdef DEBUG_BOARD_INIT |
| 616 | printf("%s: load kernel\n", __func__); |
| 617 | #endif |
| 618 | kernel_base = KERNEL_LOAD_ADDR; |
| 619 | /* now we can load the kernel */ |
pbrook | 5c130f6 | 2009-04-10 14:29:45 +0000 | [diff] [blame] | 620 | kernel_size = load_image_targphys(kernel_filename, kernel_base, |
| 621 | ram_size - kernel_base); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 622 | if (kernel_size < 0) { |
Alistair Francis | 6f76b81 | 2018-02-03 09:43:10 +0100 | [diff] [blame] | 623 | error_report("could not load kernel '%s'", kernel_filename); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 624 | exit(1); |
| 625 | } |
| 626 | /* load initrd */ |
| 627 | if (initrd_filename) { |
| 628 | initrd_base = INITRD_LOAD_ADDR; |
pbrook | 5c130f6 | 2009-04-10 14:29:45 +0000 | [diff] [blame] | 629 | initrd_size = load_image_targphys(initrd_filename, initrd_base, |
| 630 | ram_size - initrd_base); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 631 | if (initrd_size < 0) { |
Alistair Francis | 6f76b81 | 2018-02-03 09:43:10 +0100 | [diff] [blame] | 632 | error_report("could not load initial ram disk '%s'", |
| 633 | initrd_filename); |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 634 | exit(1); |
| 635 | } |
| 636 | } else { |
| 637 | initrd_base = 0; |
| 638 | initrd_size = 0; |
| 639 | } |
j_mayer | 1a6c088 | 2007-04-24 07:40:49 +0000 | [diff] [blame] | 640 | } else { |
| 641 | kernel_base = 0; |
| 642 | kernel_size = 0; |
| 643 | initrd_base = 0; |
| 644 | initrd_size = 0; |
| 645 | } |
| 646 | #ifdef DEBUG_BOARD_INIT |
| 647 | printf("%s: Done\n", __func__); |
| 648 | #endif |
| 649 | } |
| 650 | |
Andreas Färber | 8a661ae | 2015-09-19 10:49:44 +0200 | [diff] [blame] | 651 | static void taihu_class_init(ObjectClass *oc, void *data) |
Anthony Liguori | f80f9ec | 2009-05-20 18:38:09 -0500 | [diff] [blame] | 652 | { |
Andreas Färber | 8a661ae | 2015-09-19 10:49:44 +0200 | [diff] [blame] | 653 | MachineClass *mc = MACHINE_CLASS(oc); |
| 654 | |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 655 | mc->desc = "taihu"; |
| 656 | mc->init = taihu_405ep_init; |
Anthony Liguori | f80f9ec | 2009-05-20 18:38:09 -0500 | [diff] [blame] | 657 | } |
| 658 | |
Andreas Färber | 8a661ae | 2015-09-19 10:49:44 +0200 | [diff] [blame] | 659 | static const TypeInfo taihu_type = { |
| 660 | .name = MACHINE_TYPE_NAME("taihu"), |
| 661 | .parent = TYPE_MACHINE, |
| 662 | .class_init = taihu_class_init, |
| 663 | }; |
| 664 | |
| 665 | static void ppc405_machine_init(void) |
| 666 | { |
| 667 | type_register_static(&ref405ep_type); |
| 668 | type_register_static(&taihu_type); |
| 669 | } |
| 670 | |
Eduardo Habkost | 0e6aac8 | 2016-02-16 18:59:04 -0200 | [diff] [blame] | 671 | type_init(ppc405_machine_init) |