ppc405_boards.c 18.8 KB
Newer Older
J
j_mayer 已提交
1 2
/*
 * QEMU PowerPC 405 evaluation boards emulation
3
 *
J
j_mayer 已提交
4
 * Copyright (c) 2007 Jocelyn Mayer
5
 *
J
j_mayer 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
P
Peter Maydell 已提交
24
#include "qemu/osdep.h"
25
#include "qemu/units.h"
26
#include "qapi/error.h"
27 28
#include "qemu-common.h"
#include "cpu.h"
29
#include "hw/hw.h"
P
Paolo Bonzini 已提交
30
#include "hw/ppc/ppc.h"
31
#include "ppc405.h"
P
Paolo Bonzini 已提交
32 33
#include "hw/timer/m48t59.h"
#include "hw/block/flash.h"
34
#include "sysemu/sysemu.h"
35
#include "sysemu/qtest.h"
36
#include "sysemu/block-backend.h"
37
#include "hw/boards.h"
38
#include "qemu/log.h"
39
#include "qemu/error-report.h"
40
#include "hw/loader.h"
41
#include "exec/address-spaces.h"
J
j_mayer 已提交
42 43

#define BIOS_FILENAME "ppc405_rom.bin"
44
#define BIOS_SIZE (2 * MiB)
J
j_mayer 已提交
45 46 47 48 49 50

#define KERNEL_LOAD_ADDR 0x00000000
#define INITRD_LOAD_ADDR 0x01800000

#define USE_FLASH_BIOS

51
//#define DEBUG_BOARD_INIT
J
j_mayer 已提交
52 53 54 55 56 57 58 59 60 61 62

/*****************************************************************************/
/* PPC405EP reference board (IBM) */
/* Standalone board with:
 * - PowerPC 405EP CPU
 * - SDRAM (0x00000000)
 * - Flash (0xFFF80000)
 * - SRAM  (0xFFF00000)
 * - NVRAM (0xF0000000)
 * - FPGA  (0xF0300000)
 */
A
Anthony Liguori 已提交
63 64
typedef struct ref405ep_fpga_t ref405ep_fpga_t;
struct ref405ep_fpga_t {
J
j_mayer 已提交
65 66 67 68
    uint8_t reg0;
    uint8_t reg1;
};

69
static uint64_t ref405ep_fpga_readb(void *opaque, hwaddr addr, unsigned size)
J
j_mayer 已提交
70
{
A
Anthony Liguori 已提交
71
    ref405ep_fpga_t *fpga;
J
j_mayer 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    uint32_t ret;

    fpga = opaque;
    switch (addr) {
    case 0x0:
        ret = fpga->reg0;
        break;
    case 0x1:
        ret = fpga->reg1;
        break;
    default:
        ret = 0;
        break;
    }

    return ret;
}

90 91
static void ref405ep_fpga_writeb(void *opaque, hwaddr addr, uint64_t value,
                                 unsigned size)
J
j_mayer 已提交
92
{
A
Anthony Liguori 已提交
93
    ref405ep_fpga_t *fpga;
J
j_mayer 已提交
94 95 96 97 98 99 100 101 102 103 104 105 106 107

    fpga = opaque;
    switch (addr) {
    case 0x0:
        /* Read only */
        break;
    case 0x1:
        fpga->reg1 = value;
        break;
    default:
        break;
    }
}

A
Avi Kivity 已提交
108
static const MemoryRegionOps ref405ep_fpga_ops = {
109 110 111 112 113 114 115
    .read = ref405ep_fpga_readb,
    .write = ref405ep_fpga_writeb,
    .impl.min_access_size = 1,
    .impl.max_access_size = 1,
    .valid.min_access_size = 1,
    .valid.max_access_size = 4,
    .endianness = DEVICE_BIG_ENDIAN,
J
j_mayer 已提交
116 117 118 119
};

static void ref405ep_fpga_reset (void *opaque)
{
A
Anthony Liguori 已提交
120
    ref405ep_fpga_t *fpga;
J
j_mayer 已提交
121 122 123 124 125 126

    fpga = opaque;
    fpga->reg0 = 0x00;
    fpga->reg1 = 0x0F;
}

127
static void ref405ep_fpga_init(MemoryRegion *sysmem, uint32_t base)
J
j_mayer 已提交
128
{
A
Anthony Liguori 已提交
129
    ref405ep_fpga_t *fpga;
A
Avi Kivity 已提交
130
    MemoryRegion *fpga_memory = g_new(MemoryRegion, 1);
J
j_mayer 已提交
131

132
    fpga = g_malloc0(sizeof(ref405ep_fpga_t));
133
    memory_region_init_io(fpga_memory, NULL, &ref405ep_fpga_ops, fpga,
A
Avi Kivity 已提交
134 135
                          "fpga", 0x00000100);
    memory_region_add_subregion(sysmem, base, fpga_memory);
136
    qemu_register_reset(&ref405ep_fpga_reset, fpga);
J
j_mayer 已提交
137 138
}

139
static void ref405ep_init(MachineState *machine)
J
j_mayer 已提交
140
{
141 142 143 144
    ram_addr_t ram_size = machine->ram_size;
    const char *kernel_filename = machine->kernel_filename;
    const char *kernel_cmdline = machine->kernel_cmdline;
    const char *initrd_filename = machine->initrd_filename;
P
Paul Brook 已提交
145
    char *filename;
A
Anthony Liguori 已提交
146
    ppc4xx_bd_info_t bd;
J
j_mayer 已提交
147 148
    CPUPPCState *env;
    qemu_irq *pic;
149
    MemoryRegion *bios;
A
Avi Kivity 已提交
150 151
    MemoryRegion *sram = g_new(MemoryRegion, 1);
    ram_addr_t bdloc;
A
Avi Kivity 已提交
152
    MemoryRegion *ram_memories = g_malloc(2 * sizeof(*ram_memories));
A
Avi Kivity 已提交
153
    hwaddr ram_bases[2], ram_sizes[2];
154 155
    target_ulong sram_size;
    long bios_size;
J
j_mayer 已提交
156 157
    //int phy_addr = 0;
    //static int phy_addr = 1;
158 159
    target_ulong kernel_base, initrd_base;
    long kernel_size, initrd_size;
J
j_mayer 已提交
160 161
    int linux_boot;
    int fl_idx, fl_sectors, len;
G
Gerd Hoffmann 已提交
162
    DriveInfo *dinfo;
A
Avi Kivity 已提交
163
    MemoryRegion *sysmem = get_system_memory();
J
j_mayer 已提交
164 165

    /* XXX: fix this */
166 167
    memory_region_allocate_system_memory(&ram_memories[0], NULL, "ef405ep.ram",
                                         0x08000000);
A
Avi Kivity 已提交
168
    ram_bases[0] = 0;
J
j_mayer 已提交
169
    ram_sizes[0] = 0x08000000;
170
    memory_region_init(&ram_memories[1], NULL, "ef405ep.ram1", 0);
J
j_mayer 已提交
171 172
    ram_bases[1] = 0x00000000;
    ram_sizes[1] = 0x00000000;
173
    ram_size = 128 * MiB;
J
j_mayer 已提交
174 175 176
#ifdef DEBUG_BOARD_INIT
    printf("%s: register cpu\n", __func__);
#endif
A
Avi Kivity 已提交
177
    env = ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes,
178
                        33333333, &pic, kernel_filename == NULL ? 0 : 1);
J
j_mayer 已提交
179
    /* allocate SRAM */
180
    sram_size = 512 * KiB;
181
    memory_region_init_ram(sram, NULL, "ef405ep.sram", sram_size,
182
                           &error_fatal);
A
Avi Kivity 已提交
183
    memory_region_add_subregion(sysmem, 0xFFF00000, sram);
J
j_mayer 已提交
184 185 186 187 188 189
    /* allocate and load BIOS */
#ifdef DEBUG_BOARD_INIT
    printf("%s: register BIOS\n", __func__);
#endif
    fl_idx = 0;
#ifdef USE_FLASH_BIOS
G
Gerd Hoffmann 已提交
190 191
    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
    if (dinfo) {
192
        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
193

194
        bios_size = blk_getlength(blk);
J
j_mayer 已提交
195 196
        fl_sectors = (bios_size + 65535) >> 16;
#ifdef DEBUG_BOARD_INIT
197
        printf("Register parallel flash %d size %lx"
198 199
               " at addr %lx '%s' %d\n",
               fl_idx, bios_size, -bios_size,
200
               blk_name(blk), fl_sectors);
J
j_mayer 已提交
201
#endif
202 203
        pflash_cfi02_register((uint32_t)(-bios_size),
                              NULL, "ef405ep.bios", bios_size,
204
                              blk, 65536, fl_sectors, 1,
205 206
                              2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                              1);
J
j_mayer 已提交
207 208 209 210 211 212 213
        fl_idx++;
    } else
#endif
    {
#ifdef DEBUG_BOARD_INIT
        printf("Load BIOS from file\n");
#endif
214
        bios = g_new(MemoryRegion, 1);
215
        memory_region_init_ram(bios, NULL, "ef405ep.bios", BIOS_SIZE,
216
                               &error_fatal);
H
Hu Tao 已提交
217

218 219
        if (bios_name == NULL)
            bios_name = BIOS_FILENAME;
P
Paul Brook 已提交
220 221
        filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
        if (filename) {
222
            bios_size = load_image(filename, memory_region_get_ram_ptr(bios));
223
            g_free(filename);
224 225 226 227 228 229 230 231 232
            if (bios_size < 0 || bios_size > BIOS_SIZE) {
                error_report("Could not load PowerPC BIOS '%s'", bios_name);
                exit(1);
            }
            bios_size = (bios_size + 0xfff) & ~0xfff;
            memory_region_add_subregion(sysmem, (uint32_t)(-bios_size), bios);
        } else if (!qtest_enabled() || kernel_filename != NULL) {
            error_report("Could not load PowerPC BIOS '%s'", bios_name);
            exit(1);
P
Paul Brook 已提交
233
        } else {
234
            /* Avoid an uninitialized variable warning */
P
Paul Brook 已提交
235 236
            bios_size = -1;
        }
237
        memory_region_set_readonly(bios, true);
J
j_mayer 已提交
238 239 240 241 242
    }
    /* Register FPGA */
#ifdef DEBUG_BOARD_INIT
    printf("%s: register FPGA\n", __func__);
#endif
A
Avi Kivity 已提交
243
    ref405ep_fpga_init(sysmem, 0xF0300000);
J
j_mayer 已提交
244 245 246 247
    /* Register NVRAM */
#ifdef DEBUG_BOARD_INIT
    printf("%s: register NVRAM\n", __func__);
#endif
248
    m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
J
j_mayer 已提交
249 250 251 252 253 254 255 256 257
    /* Load kernel */
    linux_boot = (kernel_filename != NULL);
    if (linux_boot) {
#ifdef DEBUG_BOARD_INIT
        printf("%s: load kernel\n", __func__);
#endif
        memset(&bd, 0, sizeof(bd));
        bd.bi_memstart = 0x00000000;
        bd.bi_memsize = ram_size;
258
        bd.bi_flashstart = -bios_size;
J
j_mayer 已提交
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
        bd.bi_flashsize = -bios_size;
        bd.bi_flashoffset = 0;
        bd.bi_sramstart = 0xFFF00000;
        bd.bi_sramsize = sram_size;
        bd.bi_bootflags = 0;
        bd.bi_intfreq = 133333333;
        bd.bi_busfreq = 33333333;
        bd.bi_baudrate = 115200;
        bd.bi_s_version[0] = 'Q';
        bd.bi_s_version[1] = 'M';
        bd.bi_s_version[2] = 'U';
        bd.bi_s_version[3] = '\0';
        bd.bi_r_version[0] = 'Q';
        bd.bi_r_version[1] = 'E';
        bd.bi_r_version[2] = 'M';
        bd.bi_r_version[3] = 'U';
        bd.bi_r_version[4] = '\0';
        bd.bi_procfreq = 133333333;
        bd.bi_plb_busfreq = 33333333;
        bd.bi_pci_busfreq = 33333333;
        bd.bi_opbfreq = 33333333;
280
        bdloc = ppc405_set_bootinfo(env, &bd, 0x00000001);
J
j_mayer 已提交
281 282 283
        env->gpr[3] = bdloc;
        kernel_base = KERNEL_LOAD_ADDR;
        /* now we can load the kernel */
P
pbrook 已提交
284 285
        kernel_size = load_image_targphys(kernel_filename, kernel_base,
                                          ram_size - kernel_base);
J
j_mayer 已提交
286
        if (kernel_size < 0) {
287
            error_report("could not load kernel '%s'", kernel_filename);
J
j_mayer 已提交
288 289
            exit(1);
        }
290
        printf("Load kernel size %ld at " TARGET_FMT_lx,
P
pbrook 已提交
291
               kernel_size, kernel_base);
J
j_mayer 已提交
292 293 294
        /* load initrd */
        if (initrd_filename) {
            initrd_base = INITRD_LOAD_ADDR;
P
pbrook 已提交
295 296
            initrd_size = load_image_targphys(initrd_filename, initrd_base,
                                              ram_size - initrd_base);
J
j_mayer 已提交
297
            if (initrd_size < 0) {
298 299
                error_report("could not load initial ram disk '%s'",
                             initrd_filename);
J
j_mayer 已提交
300 301 302 303 304 305 306 307 308 309 310
                exit(1);
            }
        } else {
            initrd_base = 0;
            initrd_size = 0;
        }
        env->gpr[4] = initrd_base;
        env->gpr[5] = initrd_size;
        if (kernel_cmdline != NULL) {
            len = strlen(kernel_cmdline);
            bdloc -= ((len + 255) & ~255);
S
Stefan Weil 已提交
311
            cpu_physical_memory_write(bdloc, kernel_cmdline, len + 1);
J
j_mayer 已提交
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
            env->gpr[6] = bdloc;
            env->gpr[7] = bdloc + len;
        } else {
            env->gpr[6] = 0;
            env->gpr[7] = 0;
        }
        env->nip = KERNEL_LOAD_ADDR;
    } else {
        kernel_base = 0;
        kernel_size = 0;
        initrd_base = 0;
        initrd_size = 0;
        bdloc = 0;
    }
#ifdef DEBUG_BOARD_INIT
327
    printf("bdloc " RAM_ADDR_FMT "\n", bdloc);
J
j_mayer 已提交
328 329 330 331
    printf("%s: Done\n", __func__);
#endif
}

332
static void ref405ep_class_init(ObjectClass *oc, void *data)
333
{
334 335
    MachineClass *mc = MACHINE_CLASS(oc);

336 337 338 339
    mc->desc = "ref405ep";
    mc->init = ref405ep_init;
}

340 341 342 343 344
static const TypeInfo ref405ep_type = {
    .name = MACHINE_TYPE_NAME("ref405ep"),
    .parent = TYPE_MACHINE,
    .class_init = ref405ep_class_init,
};
J
j_mayer 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370

/*****************************************************************************/
/* AMCC Taihu evaluation board */
/* - PowerPC 405EP processor
 * - SDRAM               128 MB at 0x00000000
 * - Boot flash          2 MB   at 0xFFE00000
 * - Application flash   32 MB  at 0xFC000000
 * - 2 serial ports
 * - 2 ethernet PHY
 * - 1 USB 1.1 device    0x50000000
 * - 1 LCD display       0x50100000
 * - 1 CPLD              0x50100000
 * - 1 I2C EEPROM
 * - 1 I2C thermal sensor
 * - a set of LEDs
 * - bit-bang SPI port using GPIOs
 * - 1 EBC interface connector 0 0x50200000
 * - 1 cardbus controller + expansion slot.
 * - 1 PCI expansion slot.
 */
typedef struct taihu_cpld_t taihu_cpld_t;
struct taihu_cpld_t {
    uint8_t reg0;
    uint8_t reg1;
};

371
static uint64_t taihu_cpld_read(void *opaque, hwaddr addr, unsigned size)
J
j_mayer 已提交
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
{
    taihu_cpld_t *cpld;
    uint32_t ret;

    cpld = opaque;
    switch (addr) {
    case 0x0:
        ret = cpld->reg0;
        break;
    case 0x1:
        ret = cpld->reg1;
        break;
    default:
        ret = 0;
        break;
    }

    return ret;
}

392 393
static void taihu_cpld_write(void *opaque, hwaddr addr,
                             uint64_t value, unsigned size)
J
j_mayer 已提交
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
{
    taihu_cpld_t *cpld;

    cpld = opaque;
    switch (addr) {
    case 0x0:
        /* Read only */
        break;
    case 0x1:
        cpld->reg1 = value;
        break;
    default:
        break;
    }
}

A
Avi Kivity 已提交
410
static const MemoryRegionOps taihu_cpld_ops = {
411 412 413 414 415
    .read = taihu_cpld_read,
    .write = taihu_cpld_write,
    .impl = {
        .min_access_size = 1,
        .max_access_size = 1,
A
Avi Kivity 已提交
416 417
    },
    .endianness = DEVICE_NATIVE_ENDIAN,
J
j_mayer 已提交
418 419 420 421 422 423 424 425 426 427 428
};

static void taihu_cpld_reset (void *opaque)
{
    taihu_cpld_t *cpld;

    cpld = opaque;
    cpld->reg0 = 0x01;
    cpld->reg1 = 0x80;
}

429
static void taihu_cpld_init(MemoryRegion *sysmem, uint32_t base)
J
j_mayer 已提交
430 431
{
    taihu_cpld_t *cpld;
A
Avi Kivity 已提交
432
    MemoryRegion *cpld_memory = g_new(MemoryRegion, 1);
J
j_mayer 已提交
433

434
    cpld = g_malloc0(sizeof(taihu_cpld_t));
435
    memory_region_init_io(cpld_memory, NULL, &taihu_cpld_ops, cpld, "cpld", 0x100);
A
Avi Kivity 已提交
436
    memory_region_add_subregion(sysmem, base, cpld_memory);
437
    qemu_register_reset(&taihu_cpld_reset, cpld);
J
j_mayer 已提交
438 439
}

440
static void taihu_405ep_init(MachineState *machine)
J
j_mayer 已提交
441
{
442 443 444
    ram_addr_t ram_size = machine->ram_size;
    const char *kernel_filename = machine->kernel_filename;
    const char *initrd_filename = machine->initrd_filename;
P
Paul Brook 已提交
445
    char *filename;
J
j_mayer 已提交
446
    qemu_irq *pic;
A
Avi Kivity 已提交
447
    MemoryRegion *sysmem = get_system_memory();
448
    MemoryRegion *bios;
A
Avi Kivity 已提交
449
    MemoryRegion *ram_memories = g_malloc(2 * sizeof(*ram_memories));
H
Hu Tao 已提交
450
    MemoryRegion *ram = g_malloc0(sizeof(*ram));
A
Avi Kivity 已提交
451
    hwaddr ram_bases[2], ram_sizes[2];
452 453 454
    long bios_size;
    target_ulong kernel_base, initrd_base;
    long kernel_size, initrd_size;
J
j_mayer 已提交
455 456
    int linux_boot;
    int fl_idx, fl_sectors;
G
Gerd Hoffmann 已提交
457
    DriveInfo *dinfo;
458

J
j_mayer 已提交
459
    /* RAM is soldered to the board so the size cannot be changed */
H
Hu Tao 已提交
460 461 462 463
    ram_size = 0x08000000;
    memory_region_allocate_system_memory(ram, NULL, "taihu_405ep.ram",
                                         ram_size);

A
Avi Kivity 已提交
464
    ram_bases[0] = 0;
J
j_mayer 已提交
465
    ram_sizes[0] = 0x04000000;
H
Hu Tao 已提交
466 467 468
    memory_region_init_alias(&ram_memories[0], NULL,
                             "taihu_405ep.ram-0", ram, ram_bases[0],
                             ram_sizes[0]);
A
Avi Kivity 已提交
469
    ram_bases[1] = 0x04000000;
J
j_mayer 已提交
470
    ram_sizes[1] = 0x04000000;
H
Hu Tao 已提交
471 472 473
    memory_region_init_alias(&ram_memories[1], NULL,
                             "taihu_405ep.ram-1", ram, ram_bases[1],
                             ram_sizes[1]);
J
j_mayer 已提交
474 475 476
#ifdef DEBUG_BOARD_INIT
    printf("%s: register cpu\n", __func__);
#endif
A
Avi Kivity 已提交
477
    ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes,
478
                  33333333, &pic, kernel_filename == NULL ? 0 : 1);
J
j_mayer 已提交
479 480 481 482 483 484
    /* allocate and load BIOS */
#ifdef DEBUG_BOARD_INIT
    printf("%s: register BIOS\n", __func__);
#endif
    fl_idx = 0;
#if defined(USE_FLASH_BIOS)
G
Gerd Hoffmann 已提交
485 486
    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
    if (dinfo) {
487
        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
488

489
        bios_size = blk_getlength(blk);
J
j_mayer 已提交
490 491 492 493
        /* XXX: should check that size is 2MB */
        //        bios_size = 2 * 1024 * 1024;
        fl_sectors = (bios_size + 65535) >> 16;
#ifdef DEBUG_BOARD_INIT
494
        printf("Register parallel flash %d size %lx"
495 496
               " at addr %lx '%s' %d\n",
               fl_idx, bios_size, -bios_size,
497
               blk_name(blk), fl_sectors);
J
j_mayer 已提交
498
#endif
499 500
        pflash_cfi02_register((uint32_t)(-bios_size),
                              NULL, "taihu_405ep.bios", bios_size,
501
                              blk, 65536, fl_sectors, 1,
502 503
                              4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                              1);
J
j_mayer 已提交
504 505 506 507 508 509 510
        fl_idx++;
    } else
#endif
    {
#ifdef DEBUG_BOARD_INIT
        printf("Load BIOS from file\n");
#endif
511 512
        if (bios_name == NULL)
            bios_name = BIOS_FILENAME;
513
        bios = g_new(MemoryRegion, 1);
514
        memory_region_init_ram(bios, NULL, "taihu_405ep.bios", BIOS_SIZE,
515
                               &error_fatal);
P
Paul Brook 已提交
516 517
        filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
        if (filename) {
518
            bios_size = load_image(filename, memory_region_get_ram_ptr(bios));
519
            g_free(filename);
520 521 522 523 524 525 526 527
            if (bios_size < 0 || bios_size > BIOS_SIZE) {
                error_report("Could not load PowerPC BIOS '%s'", bios_name);
                exit(1);
            }
            bios_size = (bios_size + 0xfff) & ~0xfff;
            memory_region_add_subregion(sysmem, (uint32_t)(-bios_size), bios);
        } else if (!qtest_enabled()) {
            error_report("Could not load PowerPC BIOS '%s'", bios_name);
J
j_mayer 已提交
528 529
            exit(1);
        }
530
        memory_region_set_readonly(bios, true);
J
j_mayer 已提交
531 532
    }
    /* Register Linux flash */
G
Gerd Hoffmann 已提交
533 534
    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
    if (dinfo) {
535
        BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
536

537
        bios_size = blk_getlength(blk);
J
j_mayer 已提交
538
        /* XXX: should check that size is 32MB */
539
        bios_size = 32 * MiB;
J
j_mayer 已提交
540 541
        fl_sectors = (bios_size + 65535) >> 16;
#ifdef DEBUG_BOARD_INIT
542
        printf("Register parallel flash %d size %lx"
543 544
               " at addr " TARGET_FMT_lx " '%s'\n",
               fl_idx, bios_size, (target_ulong)0xfc000000,
545
               blk_name(blk));
J
j_mayer 已提交
546
#endif
547
        pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
548
                              blk, 65536, fl_sectors, 1,
549 550
                              4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
                              1);
J
j_mayer 已提交
551 552 553 554 555 556
        fl_idx++;
    }
    /* Register CLPD & LCD display */
#ifdef DEBUG_BOARD_INIT
    printf("%s: register CPLD\n", __func__);
#endif
A
Avi Kivity 已提交
557
    taihu_cpld_init(sysmem, 0x50100000);
J
j_mayer 已提交
558 559 560 561 562 563 564 565
    /* Load kernel */
    linux_boot = (kernel_filename != NULL);
    if (linux_boot) {
#ifdef DEBUG_BOARD_INIT
        printf("%s: load kernel\n", __func__);
#endif
        kernel_base = KERNEL_LOAD_ADDR;
        /* now we can load the kernel */
P
pbrook 已提交
566 567
        kernel_size = load_image_targphys(kernel_filename, kernel_base,
                                          ram_size - kernel_base);
J
j_mayer 已提交
568
        if (kernel_size < 0) {
569
            error_report("could not load kernel '%s'", kernel_filename);
J
j_mayer 已提交
570 571 572 573 574
            exit(1);
        }
        /* load initrd */
        if (initrd_filename) {
            initrd_base = INITRD_LOAD_ADDR;
P
pbrook 已提交
575 576
            initrd_size = load_image_targphys(initrd_filename, initrd_base,
                                              ram_size - initrd_base);
J
j_mayer 已提交
577
            if (initrd_size < 0) {
578 579
                error_report("could not load initial ram disk '%s'",
                             initrd_filename);
J
j_mayer 已提交
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
                exit(1);
            }
        } else {
            initrd_base = 0;
            initrd_size = 0;
        }
    } else {
        kernel_base = 0;
        kernel_size = 0;
        initrd_base = 0;
        initrd_size = 0;
    }
#ifdef DEBUG_BOARD_INIT
    printf("%s: Done\n", __func__);
#endif
}

597
static void taihu_class_init(ObjectClass *oc, void *data)
598
{
599 600
    MachineClass *mc = MACHINE_CLASS(oc);

601 602
    mc->desc = "taihu";
    mc->init = taihu_405ep_init;
603 604
}

605 606 607 608 609 610 611 612 613 614 615 616
static const TypeInfo taihu_type = {
    .name = MACHINE_TYPE_NAME("taihu"),
    .parent = TYPE_MACHINE,
    .class_init = taihu_class_init,
};

static void ppc405_machine_init(void)
{
    type_register_static(&ref405ep_type);
    type_register_static(&taihu_type);
}

617
type_init(ppc405_machine_init)