]> git.proxmox.com Git - mirror_qemu.git/blame - hw/ppc/ppc405_boards.c
virtex_ml507: use g_new(T, n) instead of g_malloc(sizeof(T) * n)
[mirror_qemu.git] / hw / ppc / ppc405_boards.c
CommitLineData
1a6c0886
JM
1/*
2 * QEMU PowerPC 405 evaluation boards emulation
5fafdf24 3 *
1a6c0886 4 * Copyright (c) 2007 Jocelyn Mayer
5fafdf24 5 *
1a6c0886
JM
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 */
0d75590d 24#include "qemu/osdep.h"
ab3dd749 25#include "qemu/units.h"
da34e65c 26#include "qapi/error.h"
4771d756
PB
27#include "qemu-common.h"
28#include "cpu.h"
83c9f4ca 29#include "hw/hw.h"
0d09e41a 30#include "hw/ppc/ppc.h"
47b43a1f 31#include "ppc405.h"
0d09e41a
PB
32#include "hw/timer/m48t59.h"
33#include "hw/block/flash.h"
9c17d615 34#include "sysemu/sysemu.h"
ad9990ac 35#include "sysemu/qtest.h"
4be74634 36#include "sysemu/block-backend.h"
83c9f4ca 37#include "hw/boards.h"
1de7afc9 38#include "qemu/log.h"
ad9990ac 39#include "qemu/error-report.h"
83c9f4ca 40#include "hw/loader.h"
022c62cb 41#include "exec/address-spaces.h"
1a6c0886
JM
42
43#define BIOS_FILENAME "ppc405_rom.bin"
ab3dd749 44#define BIOS_SIZE (2 * MiB)
1a6c0886
JM
45
46#define KERNEL_LOAD_ADDR 0x00000000
47#define INITRD_LOAD_ADDR 0x01800000
48
49#define USE_FLASH_BIOS
50
bf2ed917 51//#define DEBUG_BOARD_INIT
1a6c0886
JM
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 */
c227f099
AL
63typedef struct ref405ep_fpga_t ref405ep_fpga_t;
64struct ref405ep_fpga_t {
1a6c0886
JM
65 uint8_t reg0;
66 uint8_t reg1;
67};
68
878a4607 69static uint64_t ref405ep_fpga_readb(void *opaque, hwaddr addr, unsigned size)
1a6c0886 70{
c227f099 71 ref405ep_fpga_t *fpga;
1a6c0886
JM
72 uint32_t ret;
73
74 fpga = opaque;
1a6c0886
JM
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
878a4607
PM
90static void ref405ep_fpga_writeb(void *opaque, hwaddr addr, uint64_t value,
91 unsigned size)
1a6c0886 92{
c227f099 93 ref405ep_fpga_t *fpga;
1a6c0886
JM
94
95 fpga = opaque;
1a6c0886
JM
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
a682fd5c 108static const MemoryRegionOps ref405ep_fpga_ops = {
878a4607
PM
109 .read = ref405ep_fpga_readb,
110 .write = ref405ep_fpga_writeb,
111 .impl.min_access_size = 1,
112 .impl.max_access_size = 1,
113 .valid.min_access_size = 1,
114 .valid.max_access_size = 4,
115 .endianness = DEVICE_BIG_ENDIAN,
1a6c0886
JM
116};
117
118static void ref405ep_fpga_reset (void *opaque)
119{
c227f099 120 ref405ep_fpga_t *fpga;
1a6c0886
JM
121
122 fpga = opaque;
123 fpga->reg0 = 0x00;
124 fpga->reg1 = 0x0F;
125}
126
5f072e1f 127static void ref405ep_fpga_init(MemoryRegion *sysmem, uint32_t base)
1a6c0886 128{
c227f099 129 ref405ep_fpga_t *fpga;
a682fd5c 130 MemoryRegion *fpga_memory = g_new(MemoryRegion, 1);
1a6c0886 131
7267c094 132 fpga = g_malloc0(sizeof(ref405ep_fpga_t));
2c9b15ca 133 memory_region_init_io(fpga_memory, NULL, &ref405ep_fpga_ops, fpga,
a682fd5c
AK
134 "fpga", 0x00000100);
135 memory_region_add_subregion(sysmem, base, fpga_memory);
a08d4367 136 qemu_register_reset(&ref405ep_fpga_reset, fpga);
1a6c0886
JM
137}
138
3ef96221 139static void ref405ep_init(MachineState *machine)
1a6c0886 140{
3ef96221
MA
141 ram_addr_t ram_size = machine->ram_size;
142 const char *kernel_filename = machine->kernel_filename;
143 const char *kernel_cmdline = machine->kernel_cmdline;
144 const char *initrd_filename = machine->initrd_filename;
5cea8590 145 char *filename;
c227f099 146 ppc4xx_bd_info_t bd;
1a6c0886
JM
147 CPUPPCState *env;
148 qemu_irq *pic;
cfe5f011 149 MemoryRegion *bios;
a682fd5c
AK
150 MemoryRegion *sram = g_new(MemoryRegion, 1);
151 ram_addr_t bdloc;
779db4c7 152 MemoryRegion *ram_memories = g_new(MemoryRegion, 2);
a8170e5e 153 hwaddr ram_bases[2], ram_sizes[2];
093209cd
BS
154 target_ulong sram_size;
155 long bios_size;
1a6c0886
JM
156 //int phy_addr = 0;
157 //static int phy_addr = 1;
093209cd
BS
158 target_ulong kernel_base, initrd_base;
159 long kernel_size, initrd_size;
1a6c0886
JM
160 int linux_boot;
161 int fl_idx, fl_sectors, len;
751c6a17 162 DriveInfo *dinfo;
a682fd5c 163 MemoryRegion *sysmem = get_system_memory();
1a6c0886
JM
164
165 /* XXX: fix this */
e938ba0c
SP
166 memory_region_allocate_system_memory(&ram_memories[0], NULL, "ef405ep.ram",
167 0x08000000);
b6dcbe08 168 ram_bases[0] = 0;
1a6c0886 169 ram_sizes[0] = 0x08000000;
2c9b15ca 170 memory_region_init(&ram_memories[1], NULL, "ef405ep.ram1", 0);
1a6c0886
JM
171 ram_bases[1] = 0x00000000;
172 ram_sizes[1] = 0x00000000;
ab3dd749 173 ram_size = 128 * MiB;
1a6c0886
JM
174#ifdef DEBUG_BOARD_INIT
175 printf("%s: register cpu\n", __func__);
176#endif
a682fd5c 177 env = ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes,
52ce55a1 178 33333333, &pic, kernel_filename == NULL ? 0 : 1);
1a6c0886 179 /* allocate SRAM */
ab3dd749 180 sram_size = 512 * KiB;
98a99ce0 181 memory_region_init_ram(sram, NULL, "ef405ep.sram", sram_size,
f8ed85ac 182 &error_fatal);
a682fd5c 183 memory_region_add_subregion(sysmem, 0xFFF00000, sram);
1a6c0886
JM
184 /* allocate and load BIOS */
185#ifdef DEBUG_BOARD_INIT
186 printf("%s: register BIOS\n", __func__);
187#endif
1a6c0886
JM
188 fl_idx = 0;
189#ifdef USE_FLASH_BIOS
751c6a17
GH
190 dinfo = drive_get(IF_PFLASH, 0, fl_idx);
191 if (dinfo) {
4be74634 192 BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
fa1d36df 193
4be74634 194 bios_size = blk_getlength(blk);
1a6c0886
JM
195 fl_sectors = (bios_size + 65535) >> 16;
196#ifdef DEBUG_BOARD_INIT
093209cd 197 printf("Register parallel flash %d size %lx"
cfe5f011
AK
198 " at addr %lx '%s' %d\n",
199 fl_idx, bios_size, -bios_size,
4be74634 200 blk_name(blk), fl_sectors);
1a6c0886 201#endif
cfe5f011
AK
202 pflash_cfi02_register((uint32_t)(-bios_size),
203 NULL, "ef405ep.bios", bios_size,
4be74634 204 blk, 65536, fl_sectors, 1,
01e0451a
AL
205 2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
206 1);
1a6c0886
JM
207 fl_idx++;
208 } else
209#endif
210 {
211#ifdef DEBUG_BOARD_INIT
212 printf("Load BIOS from file\n");
213#endif
cfe5f011 214 bios = g_new(MemoryRegion, 1);
98a99ce0 215 memory_region_init_ram(bios, NULL, "ef405ep.bios", BIOS_SIZE,
f8ed85ac 216 &error_fatal);
e206ad48 217
1192dad8
JM
218 if (bios_name == NULL)
219 bios_name = BIOS_FILENAME;
5cea8590
PB
220 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
221 if (filename) {
214b63cd
PM
222 bios_size = load_image_size(filename,
223 memory_region_get_ram_ptr(bios),
224 BIOS_SIZE);
7267c094 225 g_free(filename);
214b63cd 226 if (bios_size < 0) {
ad9990ac
AF
227 error_report("Could not load PowerPC BIOS '%s'", bios_name);
228 exit(1);
229 }
230 bios_size = (bios_size + 0xfff) & ~0xfff;
231 memory_region_add_subregion(sysmem, (uint32_t)(-bios_size), bios);
232 } else if (!qtest_enabled() || kernel_filename != NULL) {
233 error_report("Could not load PowerPC BIOS '%s'", bios_name);
234 exit(1);
5cea8590 235 } else {
ad9990ac 236 /* Avoid an uninitialized variable warning */
5cea8590
PB
237 bios_size = -1;
238 }
cfe5f011 239 memory_region_set_readonly(bios, true);
1a6c0886 240 }
1a6c0886
JM
241 /* Register FPGA */
242#ifdef DEBUG_BOARD_INIT
243 printf("%s: register FPGA\n", __func__);
244#endif
a682fd5c 245 ref405ep_fpga_init(sysmem, 0xF0300000);
1a6c0886
JM
246 /* Register NVRAM */
247#ifdef DEBUG_BOARD_INIT
248 printf("%s: register NVRAM\n", __func__);
249#endif
6de04973 250 m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
1a6c0886
JM
251 /* Load kernel */
252 linux_boot = (kernel_filename != NULL);
253 if (linux_boot) {
254#ifdef DEBUG_BOARD_INIT
255 printf("%s: load kernel\n", __func__);
256#endif
257 memset(&bd, 0, sizeof(bd));
258 bd.bi_memstart = 0x00000000;
259 bd.bi_memsize = ram_size;
217fae2d 260 bd.bi_flashstart = -bios_size;
1a6c0886
JM
261 bd.bi_flashsize = -bios_size;
262 bd.bi_flashoffset = 0;
263 bd.bi_sramstart = 0xFFF00000;
264 bd.bi_sramsize = sram_size;
265 bd.bi_bootflags = 0;
266 bd.bi_intfreq = 133333333;
267 bd.bi_busfreq = 33333333;
268 bd.bi_baudrate = 115200;
269 bd.bi_s_version[0] = 'Q';
270 bd.bi_s_version[1] = 'M';
271 bd.bi_s_version[2] = 'U';
272 bd.bi_s_version[3] = '\0';
273 bd.bi_r_version[0] = 'Q';
274 bd.bi_r_version[1] = 'E';
275 bd.bi_r_version[2] = 'M';
276 bd.bi_r_version[3] = 'U';
277 bd.bi_r_version[4] = '\0';
278 bd.bi_procfreq = 133333333;
279 bd.bi_plb_busfreq = 33333333;
280 bd.bi_pci_busfreq = 33333333;
281 bd.bi_opbfreq = 33333333;
b8d3f5d1 282 bdloc = ppc405_set_bootinfo(env, &bd, 0x00000001);
1a6c0886
JM
283 env->gpr[3] = bdloc;
284 kernel_base = KERNEL_LOAD_ADDR;
285 /* now we can load the kernel */
5c130f65
PB
286 kernel_size = load_image_targphys(kernel_filename, kernel_base,
287 ram_size - kernel_base);
1a6c0886 288 if (kernel_size < 0) {
6f76b817 289 error_report("could not load kernel '%s'", kernel_filename);
1a6c0886
JM
290 exit(1);
291 }
093209cd 292 printf("Load kernel size %ld at " TARGET_FMT_lx,
5c130f65 293 kernel_size, kernel_base);
1a6c0886
JM
294 /* load initrd */
295 if (initrd_filename) {
296 initrd_base = INITRD_LOAD_ADDR;
5c130f65
PB
297 initrd_size = load_image_targphys(initrd_filename, initrd_base,
298 ram_size - initrd_base);
1a6c0886 299 if (initrd_size < 0) {
6f76b817
AF
300 error_report("could not load initial ram disk '%s'",
301 initrd_filename);
1a6c0886
JM
302 exit(1);
303 }
304 } else {
305 initrd_base = 0;
306 initrd_size = 0;
307 }
308 env->gpr[4] = initrd_base;
309 env->gpr[5] = initrd_size;
1a6c0886
JM
310 if (kernel_cmdline != NULL) {
311 len = strlen(kernel_cmdline);
312 bdloc -= ((len + 255) & ~255);
e1fe50dc 313 cpu_physical_memory_write(bdloc, kernel_cmdline, len + 1);
1a6c0886
JM
314 env->gpr[6] = bdloc;
315 env->gpr[7] = bdloc + len;
316 } else {
317 env->gpr[6] = 0;
318 env->gpr[7] = 0;
319 }
320 env->nip = KERNEL_LOAD_ADDR;
321 } else {
322 kernel_base = 0;
323 kernel_size = 0;
324 initrd_base = 0;
325 initrd_size = 0;
326 bdloc = 0;
327 }
328#ifdef DEBUG_BOARD_INIT
bf2ed917 329 printf("bdloc " RAM_ADDR_FMT "\n", bdloc);
1a6c0886
JM
330 printf("%s: Done\n", __func__);
331#endif
1a6c0886
JM
332}
333
8a661aea 334static void ref405ep_class_init(ObjectClass *oc, void *data)
e264d29d 335{
8a661aea
AF
336 MachineClass *mc = MACHINE_CLASS(oc);
337
e264d29d
EH
338 mc->desc = "ref405ep";
339 mc->init = ref405ep_init;
340}
341
8a661aea
AF
342static const TypeInfo ref405ep_type = {
343 .name = MACHINE_TYPE_NAME("ref405ep"),
344 .parent = TYPE_MACHINE,
345 .class_init = ref405ep_class_init,
346};
1a6c0886
JM
347
348/*****************************************************************************/
349/* AMCC Taihu evaluation board */
350/* - PowerPC 405EP processor
351 * - SDRAM 128 MB at 0x00000000
352 * - Boot flash 2 MB at 0xFFE00000
353 * - Application flash 32 MB at 0xFC000000
354 * - 2 serial ports
355 * - 2 ethernet PHY
356 * - 1 USB 1.1 device 0x50000000
357 * - 1 LCD display 0x50100000
358 * - 1 CPLD 0x50100000
359 * - 1 I2C EEPROM
360 * - 1 I2C thermal sensor
361 * - a set of LEDs
362 * - bit-bang SPI port using GPIOs
363 * - 1 EBC interface connector 0 0x50200000
364 * - 1 cardbus controller + expansion slot.
365 * - 1 PCI expansion slot.
366 */
367typedef struct taihu_cpld_t taihu_cpld_t;
368struct taihu_cpld_t {
1a6c0886
JM
369 uint8_t reg0;
370 uint8_t reg1;
371};
372
e2a176df 373static uint64_t taihu_cpld_read(void *opaque, hwaddr addr, unsigned size)
1a6c0886
JM
374{
375 taihu_cpld_t *cpld;
376 uint32_t ret;
377
378 cpld = opaque;
1a6c0886
JM
379 switch (addr) {
380 case 0x0:
381 ret = cpld->reg0;
382 break;
383 case 0x1:
384 ret = cpld->reg1;
385 break;
386 default:
387 ret = 0;
388 break;
389 }
390
391 return ret;
392}
393
e2a176df
PM
394static void taihu_cpld_write(void *opaque, hwaddr addr,
395 uint64_t value, unsigned size)
1a6c0886
JM
396{
397 taihu_cpld_t *cpld;
398
399 cpld = opaque;
1a6c0886
JM
400 switch (addr) {
401 case 0x0:
402 /* Read only */
403 break;
404 case 0x1:
405 cpld->reg1 = value;
406 break;
407 default:
408 break;
409 }
410}
411
a682fd5c 412static const MemoryRegionOps taihu_cpld_ops = {
e2a176df
PM
413 .read = taihu_cpld_read,
414 .write = taihu_cpld_write,
415 .impl = {
416 .min_access_size = 1,
417 .max_access_size = 1,
a682fd5c
AK
418 },
419 .endianness = DEVICE_NATIVE_ENDIAN,
1a6c0886
JM
420};
421
422static void taihu_cpld_reset (void *opaque)
423{
424 taihu_cpld_t *cpld;
425
426 cpld = opaque;
427 cpld->reg0 = 0x01;
428 cpld->reg1 = 0x80;
429}
430
5f072e1f 431static void taihu_cpld_init(MemoryRegion *sysmem, uint32_t base)
1a6c0886
JM
432{
433 taihu_cpld_t *cpld;
a682fd5c 434 MemoryRegion *cpld_memory = g_new(MemoryRegion, 1);
1a6c0886 435
7267c094 436 cpld = g_malloc0(sizeof(taihu_cpld_t));
2c9b15ca 437 memory_region_init_io(cpld_memory, NULL, &taihu_cpld_ops, cpld, "cpld", 0x100);
a682fd5c 438 memory_region_add_subregion(sysmem, base, cpld_memory);
a08d4367 439 qemu_register_reset(&taihu_cpld_reset, cpld);
1a6c0886
JM
440}
441
3ef96221 442static void taihu_405ep_init(MachineState *machine)
1a6c0886 443{
3ef96221
MA
444 ram_addr_t ram_size = machine->ram_size;
445 const char *kernel_filename = machine->kernel_filename;
446 const char *initrd_filename = machine->initrd_filename;
5cea8590 447 char *filename;
1a6c0886 448 qemu_irq *pic;
a682fd5c 449 MemoryRegion *sysmem = get_system_memory();
cfe5f011 450 MemoryRegion *bios;
779db4c7 451 MemoryRegion *ram_memories = g_new(MemoryRegion, 2);
e206ad48 452 MemoryRegion *ram = g_malloc0(sizeof(*ram));
a8170e5e 453 hwaddr ram_bases[2], ram_sizes[2];
093209cd
BS
454 long bios_size;
455 target_ulong kernel_base, initrd_base;
456 long kernel_size, initrd_size;
1a6c0886
JM
457 int linux_boot;
458 int fl_idx, fl_sectors;
751c6a17 459 DriveInfo *dinfo;
3b46e624 460
1a6c0886 461 /* RAM is soldered to the board so the size cannot be changed */
e206ad48
HT
462 ram_size = 0x08000000;
463 memory_region_allocate_system_memory(ram, NULL, "taihu_405ep.ram",
464 ram_size);
465
b6dcbe08 466 ram_bases[0] = 0;
1a6c0886 467 ram_sizes[0] = 0x04000000;
e206ad48
HT
468 memory_region_init_alias(&ram_memories[0], NULL,
469 "taihu_405ep.ram-0", ram, ram_bases[0],
470 ram_sizes[0]);
b6dcbe08 471 ram_bases[1] = 0x04000000;
1a6c0886 472 ram_sizes[1] = 0x04000000;
e206ad48
HT
473 memory_region_init_alias(&ram_memories[1], NULL,
474 "taihu_405ep.ram-1", ram, ram_bases[1],
475 ram_sizes[1]);
1a6c0886
JM
476#ifdef DEBUG_BOARD_INIT
477 printf("%s: register cpu\n", __func__);
478#endif
a682fd5c 479 ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes,
52ce55a1 480 33333333, &pic, kernel_filename == NULL ? 0 : 1);
1a6c0886
JM
481 /* allocate and load BIOS */
482#ifdef DEBUG_BOARD_INIT
483 printf("%s: register BIOS\n", __func__);
484#endif
485 fl_idx = 0;
486#if defined(USE_FLASH_BIOS)
751c6a17
GH
487 dinfo = drive_get(IF_PFLASH, 0, fl_idx);
488 if (dinfo) {
4be74634 489 BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
fa1d36df 490
4be74634 491 bios_size = blk_getlength(blk);
1a6c0886
JM
492 /* XXX: should check that size is 2MB */
493 // bios_size = 2 * 1024 * 1024;
494 fl_sectors = (bios_size + 65535) >> 16;
495#ifdef DEBUG_BOARD_INIT
093209cd 496 printf("Register parallel flash %d size %lx"
cfe5f011
AK
497 " at addr %lx '%s' %d\n",
498 fl_idx, bios_size, -bios_size,
4be74634 499 blk_name(blk), fl_sectors);
1a6c0886 500#endif
cfe5f011
AK
501 pflash_cfi02_register((uint32_t)(-bios_size),
502 NULL, "taihu_405ep.bios", bios_size,
4be74634 503 blk, 65536, fl_sectors, 1,
01e0451a
AL
504 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
505 1);
1a6c0886
JM
506 fl_idx++;
507 } else
508#endif
509 {
510#ifdef DEBUG_BOARD_INIT
511 printf("Load BIOS from file\n");
512#endif
1192dad8
JM
513 if (bios_name == NULL)
514 bios_name = BIOS_FILENAME;
cfe5f011 515 bios = g_new(MemoryRegion, 1);
98a99ce0 516 memory_region_init_ram(bios, NULL, "taihu_405ep.bios", BIOS_SIZE,
f8ed85ac 517 &error_fatal);
5cea8590
PB
518 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
519 if (filename) {
214b63cd
PM
520 bios_size = load_image_size(filename,
521 memory_region_get_ram_ptr(bios),
522 BIOS_SIZE);
7267c094 523 g_free(filename);
214b63cd 524 if (bios_size < 0) {
ad9990ac
AF
525 error_report("Could not load PowerPC BIOS '%s'", bios_name);
526 exit(1);
527 }
528 bios_size = (bios_size + 0xfff) & ~0xfff;
529 memory_region_add_subregion(sysmem, (uint32_t)(-bios_size), bios);
530 } else if (!qtest_enabled()) {
531 error_report("Could not load PowerPC BIOS '%s'", bios_name);
1a6c0886
JM
532 exit(1);
533 }
cfe5f011 534 memory_region_set_readonly(bios, true);
1a6c0886 535 }
1a6c0886 536 /* Register Linux flash */
751c6a17
GH
537 dinfo = drive_get(IF_PFLASH, 0, fl_idx);
538 if (dinfo) {
4be74634 539 BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
fa1d36df 540
4be74634 541 bios_size = blk_getlength(blk);
1a6c0886 542 /* XXX: should check that size is 32MB */
ab3dd749 543 bios_size = 32 * MiB;
1a6c0886
JM
544 fl_sectors = (bios_size + 65535) >> 16;
545#ifdef DEBUG_BOARD_INIT
093209cd 546 printf("Register parallel flash %d size %lx"
cfe5f011
AK
547 " at addr " TARGET_FMT_lx " '%s'\n",
548 fl_idx, bios_size, (target_ulong)0xfc000000,
4be74634 549 blk_name(blk));
1a6c0886 550#endif
cfe5f011 551 pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
4be74634 552 blk, 65536, fl_sectors, 1,
01e0451a
AL
553 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
554 1);
1a6c0886
JM
555 fl_idx++;
556 }
557 /* Register CLPD & LCD display */
558#ifdef DEBUG_BOARD_INIT
559 printf("%s: register CPLD\n", __func__);
560#endif
a682fd5c 561 taihu_cpld_init(sysmem, 0x50100000);
1a6c0886
JM
562 /* Load kernel */
563 linux_boot = (kernel_filename != NULL);
564 if (linux_boot) {
565#ifdef DEBUG_BOARD_INIT
566 printf("%s: load kernel\n", __func__);
567#endif
568 kernel_base = KERNEL_LOAD_ADDR;
569 /* now we can load the kernel */
5c130f65
PB
570 kernel_size = load_image_targphys(kernel_filename, kernel_base,
571 ram_size - kernel_base);
1a6c0886 572 if (kernel_size < 0) {
6f76b817 573 error_report("could not load kernel '%s'", kernel_filename);
1a6c0886
JM
574 exit(1);
575 }
576 /* load initrd */
577 if (initrd_filename) {
578 initrd_base = INITRD_LOAD_ADDR;
5c130f65
PB
579 initrd_size = load_image_targphys(initrd_filename, initrd_base,
580 ram_size - initrd_base);
1a6c0886 581 if (initrd_size < 0) {
6f76b817
AF
582 error_report("could not load initial ram disk '%s'",
583 initrd_filename);
1a6c0886
JM
584 exit(1);
585 }
586 } else {
587 initrd_base = 0;
588 initrd_size = 0;
589 }
1a6c0886
JM
590 } else {
591 kernel_base = 0;
592 kernel_size = 0;
593 initrd_base = 0;
594 initrd_size = 0;
595 }
596#ifdef DEBUG_BOARD_INIT
597 printf("%s: Done\n", __func__);
598#endif
599}
600
8a661aea 601static void taihu_class_init(ObjectClass *oc, void *data)
f80f9ec9 602{
8a661aea
AF
603 MachineClass *mc = MACHINE_CLASS(oc);
604
e264d29d
EH
605 mc->desc = "taihu";
606 mc->init = taihu_405ep_init;
f80f9ec9
AL
607}
608
8a661aea
AF
609static const TypeInfo taihu_type = {
610 .name = MACHINE_TYPE_NAME("taihu"),
611 .parent = TYPE_MACHINE,
612 .class_init = taihu_class_init,
613};
614
615static void ppc405_machine_init(void)
616{
617 type_register_static(&ref405ep_type);
618 type_register_static(&taihu_type);
619}
620
0e6aac87 621type_init(ppc405_machine_init)