~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to hw/ppc405_boards.c

  • Committer: Bazaar Package Importer
  • Author(s): Riku Voipio, Josh Triplett, Riku Voipio
  • Date: 2009-07-29 13:28:05 UTC
  • mfrom: (1.4.1 upstream)
  • mto: (12.1.1 sid) (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20090729132805-cau7rfexh7dawyb8
Tags: 0.10.50+git20090729-1
[ Josh Triplett ]
* Remove myself from Uploaders.

[ Riku Voipio ]
* new upstream RC version
* nuke all linux-user patches (applied upstream)
  06_exit_segfault
  12_signal_powerpc_support
  21_net_soopts
  30_syscall_ipc
  32_syscall_sysctl
  35_syscall_sockaddr
  48_signal_terminate
  55_unmux_socketcall
* nuke all other applied-upstream patches
  01_nostrip (better version upstream)
  07_i386_exec_name (can be reintroduced in debian/rules)
  50_linuxbios_isa_bios_ram (shouldn't be needed anymore)
  51_linuxbios_piix_ram_size (applied)
  56_dhcp (crap)
  60_ppc_ld (reintroduce if needed)
  64_ppc_asm_constraints (ditto)
  66_tls_ld.patch (ditto)
  81_compile_dtb.patch (applied upstream)
  82_qemu-img_decimal (ditto)
* move to git
* simplify build rules
* Correct my email address

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "qemu-log.h"
33
33
 
34
34
#define BIOS_FILENAME "ppc405_rom.bin"
35
 
#undef BIOS_SIZE
36
35
#define BIOS_SIZE (2048 * 1024)
37
36
 
38
37
#define KERNEL_LOAD_ADDR 0x00000000
162
161
    int fpga_memory;
163
162
 
164
163
    fpga = qemu_mallocz(sizeof(ref405ep_fpga_t));
165
 
    fpga_memory = cpu_register_io_memory(0, ref405ep_fpga_read,
 
164
    fpga_memory = cpu_register_io_memory(ref405ep_fpga_read,
166
165
                                         ref405ep_fpga_write, fpga);
167
166
    cpu_register_physical_memory(base, 0x00000100, fpga_memory);
168
167
    ref405ep_fpga_reset(fpga);
169
168
    qemu_register_reset(&ref405ep_fpga_reset, fpga);
170
169
}
171
170
 
172
 
static void ref405ep_init (ram_addr_t ram_size, int vga_ram_size,
 
171
static void ref405ep_init (ram_addr_t ram_size,
173
172
                           const char *boot_device,
174
173
                           const char *kernel_filename,
175
174
                           const char *kernel_cmdline,
176
175
                           const char *initrd_filename,
177
176
                           const char *cpu_model)
178
177
{
179
 
    char buf[1024];
 
178
    char *filename;
180
179
    ppc4xx_bd_info_t bd;
181
180
    CPUPPCState *env;
182
181
    qemu_irq *pic;
189
188
    int linux_boot;
190
189
    int fl_idx, fl_sectors, len;
191
190
    int ppc_boot_device = boot_device[0];
192
 
    int index;
 
191
    DriveInfo *dinfo;
193
192
 
194
193
    /* XXX: fix this */
195
 
    ram_bases[0] = 0x00000000;
 
194
    ram_bases[0] = qemu_ram_alloc(0x08000000);
196
195
    ram_sizes[0] = 0x08000000;
197
196
    ram_bases[1] = 0x00000000;
198
197
    ram_sizes[1] = 0x00000000;
200
199
#ifdef DEBUG_BOARD_INIT
201
200
    printf("%s: register cpu\n", __func__);
202
201
#endif
203
 
    env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic, &sram_offset,
 
202
    env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic,
204
203
                        kernel_filename == NULL ? 0 : 1);
205
204
    /* allocate SRAM */
 
205
    sram_size = 512 * 1024;
 
206
    sram_offset = qemu_ram_alloc(sram_size);
206
207
#ifdef DEBUG_BOARD_INIT
207
208
    printf("%s: register SRAM at offset %08lx\n", __func__, sram_offset);
208
209
#endif
209
 
    sram_size = 512 * 1024;
210
210
    cpu_register_physical_memory(0xFFF00000, sram_size,
211
211
                                 sram_offset | IO_MEM_RAM);
212
212
    /* allocate and load BIOS */
213
213
#ifdef DEBUG_BOARD_INIT
214
214
    printf("%s: register BIOS\n", __func__);
215
215
#endif
216
 
    bios_offset = sram_offset + sram_size;
217
216
    fl_idx = 0;
218
217
#ifdef USE_FLASH_BIOS
219
 
    index = drive_get_index(IF_PFLASH, 0, fl_idx);
220
 
    if (index != -1) {
221
 
        bios_size = bdrv_getlength(drives_table[index].bdrv);
 
218
    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
 
219
    if (dinfo) {
 
220
        bios_size = bdrv_getlength(dinfo->bdrv);
 
221
        bios_offset = qemu_ram_alloc(bios_size);
222
222
        fl_sectors = (bios_size + 65535) >> 16;
223
223
#ifdef DEBUG_BOARD_INIT
224
224
        printf("Register parallel flash %d size " ADDRX " at offset %08lx "
225
225
               " addr " ADDRX " '%s' %d\n",
226
226
               fl_idx, bios_size, bios_offset, -bios_size,
227
 
               bdrv_get_device_name(drives_table[index].bdrv), fl_sectors);
 
227
               bdrv_get_device_name(dinfo->bdrv), fl_sectors);
228
228
#endif
229
229
        pflash_cfi02_register((uint32_t)(-bios_size), bios_offset,
230
 
                              drives_table[index].bdrv, 65536, fl_sectors, 1,
 
230
                              dinfo->bdrv, 65536, fl_sectors, 1,
231
231
                              2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
232
232
        fl_idx++;
233
233
    } else
236
236
#ifdef DEBUG_BOARD_INIT
237
237
        printf("Load BIOS from file\n");
238
238
#endif
 
239
        bios_offset = qemu_ram_alloc(BIOS_SIZE);
239
240
        if (bios_name == NULL)
240
241
            bios_name = BIOS_FILENAME;
241
 
        snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
242
 
        bios_size = load_image(buf, phys_ram_base + bios_offset);
 
242
        filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
 
243
        if (filename) {
 
244
            bios_size = load_image(filename, qemu_get_ram_ptr(bios_offset));
 
245
            qemu_free(filename);
 
246
        } else {
 
247
            bios_size = -1;
 
248
        }
243
249
        if (bios_size < 0 || bios_size > BIOS_SIZE) {
244
 
            fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", buf);
 
250
            fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n",
 
251
                    bios_name);
245
252
            exit(1);
246
253
        }
247
254
        bios_size = (bios_size + 0xfff) & ~0xfff;
248
255
        cpu_register_physical_memory((uint32_t)(-bios_size),
249
256
                                     bios_size, bios_offset | IO_MEM_ROM);
250
257
    }
251
 
    bios_offset += bios_size;
252
258
    /* Register FPGA */
253
259
#ifdef DEBUG_BOARD_INIT
254
260
    printf("%s: register FPGA\n", __func__);
294
300
        env->gpr[3] = bdloc;
295
301
        kernel_base = KERNEL_LOAD_ADDR;
296
302
        /* now we can load the kernel */
297
 
        kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
 
303
        kernel_size = load_image_targphys(kernel_filename, kernel_base,
 
304
                                          ram_size - kernel_base);
298
305
        if (kernel_size < 0) {
299
306
            fprintf(stderr, "qemu: could not load kernel '%s'\n",
300
307
                    kernel_filename);
301
308
            exit(1);
302
309
        }
303
 
        printf("Load kernel size " TARGET_FMT_ld " at " TARGET_FMT_lx
304
 
               " %02x %02x %02x %02x\n", kernel_size, kernel_base,
305
 
               *(char *)(phys_ram_base + kernel_base),
306
 
               *(char *)(phys_ram_base + kernel_base + 1),
307
 
               *(char *)(phys_ram_base + kernel_base + 2),
308
 
               *(char *)(phys_ram_base + kernel_base + 3));
 
310
        printf("Load kernel size " TARGET_FMT_ld " at " TARGET_FMT_lx,
 
311
               kernel_size, kernel_base);
309
312
        /* load initrd */
310
313
        if (initrd_filename) {
311
314
            initrd_base = INITRD_LOAD_ADDR;
312
 
            initrd_size = load_image(initrd_filename,
313
 
                                     phys_ram_base + initrd_base);
 
315
            initrd_size = load_image_targphys(initrd_filename, initrd_base,
 
316
                                              ram_size - initrd_base);
314
317
            if (initrd_size < 0) {
315
318
                fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
316
319
                        initrd_filename);
326
329
        if (kernel_cmdline != NULL) {
327
330
            len = strlen(kernel_cmdline);
328
331
            bdloc -= ((len + 255) & ~255);
329
 
            memcpy(phys_ram_base + bdloc, kernel_cmdline, len + 1);
 
332
            cpu_physical_memory_write(bdloc, (void *)kernel_cmdline, len + 1);
330
333
            env->gpr[6] = bdloc;
331
334
            env->gpr[7] = bdloc + len;
332
335
        } else {
344
347
#ifdef DEBUG_BOARD_INIT
345
348
    printf("%s: Done\n", __func__);
346
349
#endif
347
 
    printf("bdloc %016lx %s\n",
348
 
           (unsigned long)bdloc, (char *)(phys_ram_base + bdloc));
 
350
    printf("bdloc %016lx\n", (unsigned long)bdloc);
349
351
}
350
352
 
351
 
QEMUMachine ref405ep_machine = {
 
353
static QEMUMachine ref405ep_machine = {
352
354
    .name = "ref405ep",
353
355
    .desc = "ref405ep",
354
356
    .init = ref405ep_init,
355
 
    .ram_require = (128 * 1024 * 1024 + 4096 + 512 * 1024 + BIOS_SIZE) | RAMSIZE_FIXED,
356
357
};
357
358
 
358
359
/*****************************************************************************/
484
485
    int cpld_memory;
485
486
 
486
487
    cpld = qemu_mallocz(sizeof(taihu_cpld_t));
487
 
    cpld_memory = cpu_register_io_memory(0, taihu_cpld_read,
 
488
    cpld_memory = cpu_register_io_memory(taihu_cpld_read,
488
489
                                         taihu_cpld_write, cpld);
489
490
    cpu_register_physical_memory(base, 0x00000100, cpld_memory);
490
491
    taihu_cpld_reset(cpld);
491
492
    qemu_register_reset(&taihu_cpld_reset, cpld);
492
493
}
493
494
 
494
 
static void taihu_405ep_init(ram_addr_t ram_size, int vga_ram_size,
 
495
static void taihu_405ep_init(ram_addr_t ram_size,
495
496
                             const char *boot_device,
496
497
                             const char *kernel_filename,
497
498
                             const char *kernel_cmdline,
498
499
                             const char *initrd_filename,
499
500
                             const char *cpu_model)
500
501
{
501
 
    char buf[1024];
 
502
    char *filename;
502
503
    CPUPPCState *env;
503
504
    qemu_irq *pic;
504
505
    ram_addr_t bios_offset;
508
509
    int linux_boot;
509
510
    int fl_idx, fl_sectors;
510
511
    int ppc_boot_device = boot_device[0];
511
 
    int index;
 
512
    DriveInfo *dinfo;
512
513
 
513
514
    /* RAM is soldered to the board so the size cannot be changed */
514
 
    ram_bases[0] = 0x00000000;
 
515
    ram_bases[0] = qemu_ram_alloc(0x04000000);
515
516
    ram_sizes[0] = 0x04000000;
516
 
    ram_bases[1] = 0x04000000;
 
517
    ram_bases[1] = qemu_ram_alloc(0x04000000);
517
518
    ram_sizes[1] = 0x04000000;
 
519
    ram_size = 0x08000000;
518
520
#ifdef DEBUG_BOARD_INIT
519
521
    printf("%s: register cpu\n", __func__);
520
522
#endif
521
 
    env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic, &bios_offset,
 
523
    env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic,
522
524
                        kernel_filename == NULL ? 0 : 1);
523
525
    /* allocate and load BIOS */
524
526
#ifdef DEBUG_BOARD_INIT
526
528
#endif
527
529
    fl_idx = 0;
528
530
#if defined(USE_FLASH_BIOS)
529
 
    index = drive_get_index(IF_PFLASH, 0, fl_idx);
530
 
    if (index != -1) {
531
 
        bios_size = bdrv_getlength(drives_table[index].bdrv);
 
531
    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
 
532
    if (dinfo) {
 
533
        bios_size = bdrv_getlength(dinfo->bdrv);
532
534
        /* XXX: should check that size is 2MB */
533
535
        //        bios_size = 2 * 1024 * 1024;
534
536
        fl_sectors = (bios_size + 65535) >> 16;
 
537
        bios_offset = qemu_ram_alloc(bios_size);
535
538
#ifdef DEBUG_BOARD_INIT
536
539
        printf("Register parallel flash %d size " ADDRX " at offset %08lx "
537
540
               " addr " ADDRX " '%s' %d\n",
538
541
               fl_idx, bios_size, bios_offset, -bios_size,
539
 
               bdrv_get_device_name(drives_table[index].bdrv), fl_sectors);
 
542
               bdrv_get_device_name(dinfo->bdrv), fl_sectors);
540
543
#endif
541
544
        pflash_cfi02_register((uint32_t)(-bios_size), bios_offset,
542
 
                              drives_table[index].bdrv, 65536, fl_sectors, 1,
 
545
                              dinfo->bdrv, 65536, fl_sectors, 1,
543
546
                              4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
544
547
        fl_idx++;
545
548
    } else
550
553
#endif
551
554
        if (bios_name == NULL)
552
555
            bios_name = BIOS_FILENAME;
553
 
        snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
554
 
        bios_size = load_image(buf, phys_ram_base + bios_offset);
 
556
        bios_offset = qemu_ram_alloc(BIOS_SIZE);
 
557
        filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
 
558
        if (filename) {
 
559
            bios_size = load_image(filename, qemu_get_ram_ptr(bios_offset));
 
560
        } else {
 
561
            bios_size = -1;
 
562
        }
555
563
        if (bios_size < 0 || bios_size > BIOS_SIZE) {
556
 
            fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", buf);
 
564
            fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n",
 
565
                    bios_name);
557
566
            exit(1);
558
567
        }
559
568
        bios_size = (bios_size + 0xfff) & ~0xfff;
560
569
        cpu_register_physical_memory((uint32_t)(-bios_size),
561
570
                                     bios_size, bios_offset | IO_MEM_ROM);
562
571
    }
563
 
    bios_offset += bios_size;
564
572
    /* Register Linux flash */
565
 
    index = drive_get_index(IF_PFLASH, 0, fl_idx);
566
 
    if (index != -1) {
567
 
        bios_size = bdrv_getlength(drives_table[index].bdrv);
 
573
    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
 
574
    if (dinfo) {
 
575
        bios_size = bdrv_getlength(dinfo->bdrv);
568
576
        /* XXX: should check that size is 32MB */
569
577
        bios_size = 32 * 1024 * 1024;
570
578
        fl_sectors = (bios_size + 65535) >> 16;
572
580
        printf("Register parallel flash %d size " ADDRX " at offset %08lx "
573
581
               " addr " ADDRX " '%s'\n",
574
582
               fl_idx, bios_size, bios_offset, (target_ulong)0xfc000000,
575
 
               bdrv_get_device_name(drives_table[index].bdrv));
 
583
               bdrv_get_device_name(dinfo->bdrv));
576
584
#endif
 
585
        bios_offset = qemu_ram_alloc(bios_size);
577
586
        pflash_cfi02_register(0xfc000000, bios_offset,
578
 
                              drives_table[index].bdrv, 65536, fl_sectors, 1,
 
587
                              dinfo->bdrv, 65536, fl_sectors, 1,
579
588
                              4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
580
589
        fl_idx++;
581
590
    }
592
601
#endif
593
602
        kernel_base = KERNEL_LOAD_ADDR;
594
603
        /* now we can load the kernel */
595
 
        kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
 
604
        kernel_size = load_image_targphys(kernel_filename, kernel_base,
 
605
                                          ram_size - kernel_base);
596
606
        if (kernel_size < 0) {
597
607
            fprintf(stderr, "qemu: could not load kernel '%s'\n",
598
608
                    kernel_filename);
601
611
        /* load initrd */
602
612
        if (initrd_filename) {
603
613
            initrd_base = INITRD_LOAD_ADDR;
604
 
            initrd_size = load_image(initrd_filename,
605
 
                                     phys_ram_base + initrd_base);
 
614
            initrd_size = load_image_targphys(initrd_filename, initrd_base,
 
615
                                              ram_size - initrd_base);
606
616
            if (initrd_size < 0) {
607
617
                fprintf(stderr,
608
618
                        "qemu: could not load initial ram disk '%s'\n",
625
635
#endif
626
636
}
627
637
 
628
 
QEMUMachine taihu_machine = {
629
 
    "taihu",
630
 
    "taihu",
631
 
    taihu_405ep_init,
632
 
    (128 * 1024 * 1024 + 4096 + BIOS_SIZE + 32 * 1024 * 1024) | RAMSIZE_FIXED,
 
638
static QEMUMachine taihu_machine = {
 
639
    .name = "taihu",
 
640
    .desc = "taihu",
 
641
    .init = taihu_405ep_init,
633
642
};
 
643
 
 
644
static void ppc405_machine_init(void)
 
645
{
 
646
    qemu_register_machine(&ref405ep_machine);
 
647
    qemu_register_machine(&taihu_machine);
 
648
}
 
649
 
 
650
machine_init(ppc405_machine_init);