2 * QEMU PowerPC 405 evaluation boards emulation
4 * Copyright (c) 2007 Jocelyn Mayer
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
35 #define BIOS_FILENAME "ppc405_rom.bin"
36 #define BIOS_SIZE (2048 * 1024)
38 #define KERNEL_LOAD_ADDR 0x00000000
39 #define INITRD_LOAD_ADDR 0x01800000
41 #define USE_FLASH_BIOS
43 #define DEBUG_BOARD_INIT
45 /*****************************************************************************/
46 /* PPC405EP reference board (IBM) */
47 /* Standalone board with:
49 * - SDRAM (0x00000000)
50 * - Flash (0xFFF80000)
52 * - NVRAM (0xF0000000)
55 typedef struct ref405ep_fpga_t ref405ep_fpga_t
;
56 struct ref405ep_fpga_t
{
61 static uint32_t ref405ep_fpga_readb (void *opaque
, target_phys_addr_t addr
)
63 ref405ep_fpga_t
*fpga
;
82 static void ref405ep_fpga_writeb (void *opaque
,
83 target_phys_addr_t addr
, uint32_t value
)
85 ref405ep_fpga_t
*fpga
;
100 static uint32_t ref405ep_fpga_readw (void *opaque
, target_phys_addr_t addr
)
104 ret
= ref405ep_fpga_readb(opaque
, addr
) << 8;
105 ret
|= ref405ep_fpga_readb(opaque
, addr
+ 1);
110 static void ref405ep_fpga_writew (void *opaque
,
111 target_phys_addr_t addr
, uint32_t value
)
113 ref405ep_fpga_writeb(opaque
, addr
, (value
>> 8) & 0xFF);
114 ref405ep_fpga_writeb(opaque
, addr
+ 1, value
& 0xFF);
117 static uint32_t ref405ep_fpga_readl (void *opaque
, target_phys_addr_t addr
)
121 ret
= ref405ep_fpga_readb(opaque
, addr
) << 24;
122 ret
|= ref405ep_fpga_readb(opaque
, addr
+ 1) << 16;
123 ret
|= ref405ep_fpga_readb(opaque
, addr
+ 2) << 8;
124 ret
|= ref405ep_fpga_readb(opaque
, addr
+ 3);
129 static void ref405ep_fpga_writel (void *opaque
,
130 target_phys_addr_t addr
, uint32_t value
)
132 ref405ep_fpga_writeb(opaque
, addr
, (value
>> 24) & 0xFF);
133 ref405ep_fpga_writeb(opaque
, addr
+ 1, (value
>> 16) & 0xFF);
134 ref405ep_fpga_writeb(opaque
, addr
+ 2, (value
>> 8) & 0xFF);
135 ref405ep_fpga_writeb(opaque
, addr
+ 3, value
& 0xFF);
138 static CPUReadMemoryFunc
* const ref405ep_fpga_read
[] = {
139 &ref405ep_fpga_readb
,
140 &ref405ep_fpga_readw
,
141 &ref405ep_fpga_readl
,
144 static CPUWriteMemoryFunc
* const ref405ep_fpga_write
[] = {
145 &ref405ep_fpga_writeb
,
146 &ref405ep_fpga_writew
,
147 &ref405ep_fpga_writel
,
150 static void ref405ep_fpga_reset (void *opaque
)
152 ref405ep_fpga_t
*fpga
;
159 static void ref405ep_fpga_init (uint32_t base
)
161 ref405ep_fpga_t
*fpga
;
164 fpga
= qemu_mallocz(sizeof(ref405ep_fpga_t
));
165 fpga_memory
= cpu_register_io_memory(ref405ep_fpga_read
,
166 ref405ep_fpga_write
, fpga
);
167 cpu_register_physical_memory(base
, 0x00000100, fpga_memory
);
168 qemu_register_reset(&ref405ep_fpga_reset
, fpga
);
171 static void ref405ep_init (QEMUMachine
*machine
, QemuOpts
*opts
)
173 ram_addr_t ram_size
= qemu_opt_get_number(opts
, "ram_size", 0);
174 const char *kernel_filename
= qemu_opt_get(opts
, "kernel");
175 const char *kernel_cmdline
= qemu_opt_get(opts
, "cmdline");
176 const char *initrd_filename
= qemu_opt_get(opts
, "initrd");
181 ram_addr_t sram_offset
, bios_offset
, bdloc
;
182 target_phys_addr_t ram_bases
[2], ram_sizes
[2];
183 target_ulong sram_size
, bios_size
;
185 //static int phy_addr = 1;
186 target_ulong kernel_base
, kernel_size
, initrd_base
, initrd_size
;
188 int fl_idx
, fl_sectors
, len
;
192 ram_bases
[0] = qemu_ram_alloc(0x08000000);
193 ram_sizes
[0] = 0x08000000;
194 ram_bases
[1] = 0x00000000;
195 ram_sizes
[1] = 0x00000000;
196 ram_size
= 128 * 1024 * 1024;
197 #ifdef DEBUG_BOARD_INIT
198 printf("%s: register cpu\n", __func__
);
200 env
= ppc405ep_init(ram_bases
, ram_sizes
, 33333333, &pic
,
201 kernel_filename
== NULL
? 0 : 1);
203 sram_size
= 512 * 1024;
204 sram_offset
= qemu_ram_alloc(sram_size
);
205 #ifdef DEBUG_BOARD_INIT
206 printf("%s: register SRAM at offset %08lx\n", __func__
, sram_offset
);
208 cpu_register_physical_memory(0xFFF00000, sram_size
,
209 sram_offset
| IO_MEM_RAM
);
210 /* allocate and load BIOS */
211 #ifdef DEBUG_BOARD_INIT
212 printf("%s: register BIOS\n", __func__
);
215 #ifdef USE_FLASH_BIOS
216 dinfo
= drive_get(IF_PFLASH
, 0, fl_idx
);
218 bios_size
= bdrv_getlength(dinfo
->bdrv
);
219 bios_offset
= qemu_ram_alloc(bios_size
);
220 fl_sectors
= (bios_size
+ 65535) >> 16;
221 #ifdef DEBUG_BOARD_INIT
222 printf("Register parallel flash %d size " TARGET_FMT_lx
223 " at offset %08lx addr " TARGET_FMT_lx
" '%s' %d\n",
224 fl_idx
, bios_size
, bios_offset
, -bios_size
,
225 bdrv_get_device_name(dinfo
->bdrv
), fl_sectors
);
227 pflash_cfi02_register((uint32_t)(-bios_size
), bios_offset
,
228 dinfo
->bdrv
, 65536, fl_sectors
, 1,
229 2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
235 #ifdef DEBUG_BOARD_INIT
236 printf("Load BIOS from file\n");
238 bios_offset
= qemu_ram_alloc(BIOS_SIZE
);
239 if (bios_name
== NULL
)
240 bios_name
= BIOS_FILENAME
;
241 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
243 bios_size
= load_image(filename
, qemu_get_ram_ptr(bios_offset
));
248 if (bios_size
< 0 || bios_size
> BIOS_SIZE
) {
249 fprintf(stderr
, "qemu: could not load PowerPC bios '%s'\n",
253 bios_size
= (bios_size
+ 0xfff) & ~0xfff;
254 cpu_register_physical_memory((uint32_t)(-bios_size
),
255 bios_size
, bios_offset
| IO_MEM_ROM
);
258 #ifdef DEBUG_BOARD_INIT
259 printf("%s: register FPGA\n", __func__
);
261 ref405ep_fpga_init(0xF0300000);
263 #ifdef DEBUG_BOARD_INIT
264 printf("%s: register NVRAM\n", __func__
);
266 m48t59_init(NULL
, 0xF0000000, 0, 8192, 8);
268 linux_boot
= (kernel_filename
!= NULL
);
270 #ifdef DEBUG_BOARD_INIT
271 printf("%s: load kernel\n", __func__
);
273 memset(&bd
, 0, sizeof(bd
));
274 bd
.bi_memstart
= 0x00000000;
275 bd
.bi_memsize
= ram_size
;
276 bd
.bi_flashstart
= -bios_size
;
277 bd
.bi_flashsize
= -bios_size
;
278 bd
.bi_flashoffset
= 0;
279 bd
.bi_sramstart
= 0xFFF00000;
280 bd
.bi_sramsize
= sram_size
;
282 bd
.bi_intfreq
= 133333333;
283 bd
.bi_busfreq
= 33333333;
284 bd
.bi_baudrate
= 115200;
285 bd
.bi_s_version
[0] = 'Q';
286 bd
.bi_s_version
[1] = 'M';
287 bd
.bi_s_version
[2] = 'U';
288 bd
.bi_s_version
[3] = '\0';
289 bd
.bi_r_version
[0] = 'Q';
290 bd
.bi_r_version
[1] = 'E';
291 bd
.bi_r_version
[2] = 'M';
292 bd
.bi_r_version
[3] = 'U';
293 bd
.bi_r_version
[4] = '\0';
294 bd
.bi_procfreq
= 133333333;
295 bd
.bi_plb_busfreq
= 33333333;
296 bd
.bi_pci_busfreq
= 33333333;
297 bd
.bi_opbfreq
= 33333333;
298 bdloc
= ppc405_set_bootinfo(env
, &bd
, 0x00000001);
300 kernel_base
= KERNEL_LOAD_ADDR
;
301 /* now we can load the kernel */
302 kernel_size
= load_image_targphys(kernel_filename
, kernel_base
,
303 ram_size
- kernel_base
);
304 if (kernel_size
< 0) {
305 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
309 printf("Load kernel size " TARGET_FMT_ld
" at " TARGET_FMT_lx
,
310 kernel_size
, kernel_base
);
312 if (initrd_filename
) {
313 initrd_base
= INITRD_LOAD_ADDR
;
314 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
315 ram_size
- initrd_base
);
316 if (initrd_size
< 0) {
317 fprintf(stderr
, "qemu: could not load initial ram disk '%s'\n",
325 env
->gpr
[4] = initrd_base
;
326 env
->gpr
[5] = initrd_size
;
327 if (kernel_cmdline
!= NULL
) {
328 len
= strlen(kernel_cmdline
);
329 bdloc
-= ((len
+ 255) & ~255);
330 cpu_physical_memory_write(bdloc
, (void *)kernel_cmdline
, len
+ 1);
332 env
->gpr
[7] = bdloc
+ len
;
337 env
->nip
= KERNEL_LOAD_ADDR
;
345 #ifdef DEBUG_BOARD_INIT
346 printf("%s: Done\n", __func__
);
348 printf("bdloc %016lx\n", (unsigned long)bdloc
);
351 static QEMUMachine ref405ep_machine
= {
354 .init
= ref405ep_init
,
357 /*****************************************************************************/
358 /* AMCC Taihu evaluation board */
359 /* - PowerPC 405EP processor
360 * - SDRAM 128 MB at 0x00000000
361 * - Boot flash 2 MB at 0xFFE00000
362 * - Application flash 32 MB at 0xFC000000
365 * - 1 USB 1.1 device 0x50000000
366 * - 1 LCD display 0x50100000
367 * - 1 CPLD 0x50100000
369 * - 1 I2C thermal sensor
371 * - bit-bang SPI port using GPIOs
372 * - 1 EBC interface connector 0 0x50200000
373 * - 1 cardbus controller + expansion slot.
374 * - 1 PCI expansion slot.
376 typedef struct taihu_cpld_t taihu_cpld_t
;
377 struct taihu_cpld_t
{
382 static uint32_t taihu_cpld_readb (void *opaque
, target_phys_addr_t addr
)
403 static void taihu_cpld_writeb (void *opaque
,
404 target_phys_addr_t addr
, uint32_t value
)
421 static uint32_t taihu_cpld_readw (void *opaque
, target_phys_addr_t addr
)
425 ret
= taihu_cpld_readb(opaque
, addr
) << 8;
426 ret
|= taihu_cpld_readb(opaque
, addr
+ 1);
431 static void taihu_cpld_writew (void *opaque
,
432 target_phys_addr_t addr
, uint32_t value
)
434 taihu_cpld_writeb(opaque
, addr
, (value
>> 8) & 0xFF);
435 taihu_cpld_writeb(opaque
, addr
+ 1, value
& 0xFF);
438 static uint32_t taihu_cpld_readl (void *opaque
, target_phys_addr_t addr
)
442 ret
= taihu_cpld_readb(opaque
, addr
) << 24;
443 ret
|= taihu_cpld_readb(opaque
, addr
+ 1) << 16;
444 ret
|= taihu_cpld_readb(opaque
, addr
+ 2) << 8;
445 ret
|= taihu_cpld_readb(opaque
, addr
+ 3);
450 static void taihu_cpld_writel (void *opaque
,
451 target_phys_addr_t addr
, uint32_t value
)
453 taihu_cpld_writel(opaque
, addr
, (value
>> 24) & 0xFF);
454 taihu_cpld_writel(opaque
, addr
+ 1, (value
>> 16) & 0xFF);
455 taihu_cpld_writel(opaque
, addr
+ 2, (value
>> 8) & 0xFF);
456 taihu_cpld_writeb(opaque
, addr
+ 3, value
& 0xFF);
459 static CPUReadMemoryFunc
* const taihu_cpld_read
[] = {
465 static CPUWriteMemoryFunc
* const taihu_cpld_write
[] = {
471 static void taihu_cpld_reset (void *opaque
)
480 static void taihu_cpld_init (uint32_t base
)
485 cpld
= qemu_mallocz(sizeof(taihu_cpld_t
));
486 cpld_memory
= cpu_register_io_memory(taihu_cpld_read
,
487 taihu_cpld_write
, cpld
);
488 cpu_register_physical_memory(base
, 0x00000100, cpld_memory
);
489 qemu_register_reset(&taihu_cpld_reset
, cpld
);
492 static void taihu_405ep_init(QEMUMachine
*machine
, QemuOpts
*opts
)
494 ram_addr_t ram_size
= qemu_opt_get_number(opts
, "ram_size", 0);
495 const char *kernel_filename
= qemu_opt_get(opts
, "kernel");
496 const char *initrd_filename
= qemu_opt_get(opts
, "initrd");
500 ram_addr_t bios_offset
;
501 target_phys_addr_t ram_bases
[2], ram_sizes
[2];
502 target_ulong bios_size
;
503 target_ulong kernel_base
, kernel_size
, initrd_base
, initrd_size
;
505 int fl_idx
, fl_sectors
;
508 /* RAM is soldered to the board so the size cannot be changed */
509 ram_bases
[0] = qemu_ram_alloc(0x04000000);
510 ram_sizes
[0] = 0x04000000;
511 ram_bases
[1] = qemu_ram_alloc(0x04000000);
512 ram_sizes
[1] = 0x04000000;
513 ram_size
= 0x08000000;
514 #ifdef DEBUG_BOARD_INIT
515 printf("%s: register cpu\n", __func__
);
517 env
= ppc405ep_init(ram_bases
, ram_sizes
, 33333333, &pic
,
518 kernel_filename
== NULL
? 0 : 1);
519 /* allocate and load BIOS */
520 #ifdef DEBUG_BOARD_INIT
521 printf("%s: register BIOS\n", __func__
);
524 #if defined(USE_FLASH_BIOS)
525 dinfo
= drive_get(IF_PFLASH
, 0, fl_idx
);
527 bios_size
= bdrv_getlength(dinfo
->bdrv
);
528 /* XXX: should check that size is 2MB */
529 // bios_size = 2 * 1024 * 1024;
530 fl_sectors
= (bios_size
+ 65535) >> 16;
531 bios_offset
= qemu_ram_alloc(bios_size
);
532 #ifdef DEBUG_BOARD_INIT
533 printf("Register parallel flash %d size " TARGET_FMT_lx
534 " at offset %08lx addr " TARGET_FMT_lx
" '%s' %d\n",
535 fl_idx
, bios_size
, bios_offset
, -bios_size
,
536 bdrv_get_device_name(dinfo
->bdrv
), fl_sectors
);
538 pflash_cfi02_register((uint32_t)(-bios_size
), bios_offset
,
539 dinfo
->bdrv
, 65536, fl_sectors
, 1,
540 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
546 #ifdef DEBUG_BOARD_INIT
547 printf("Load BIOS from file\n");
549 if (bios_name
== NULL
)
550 bios_name
= BIOS_FILENAME
;
551 bios_offset
= qemu_ram_alloc(BIOS_SIZE
);
552 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
554 bios_size
= load_image(filename
, qemu_get_ram_ptr(bios_offset
));
558 if (bios_size
< 0 || bios_size
> BIOS_SIZE
) {
559 fprintf(stderr
, "qemu: could not load PowerPC bios '%s'\n",
563 bios_size
= (bios_size
+ 0xfff) & ~0xfff;
564 cpu_register_physical_memory((uint32_t)(-bios_size
),
565 bios_size
, bios_offset
| IO_MEM_ROM
);
567 /* Register Linux flash */
568 dinfo
= drive_get(IF_PFLASH
, 0, fl_idx
);
570 bios_size
= bdrv_getlength(dinfo
->bdrv
);
571 /* XXX: should check that size is 32MB */
572 bios_size
= 32 * 1024 * 1024;
573 fl_sectors
= (bios_size
+ 65535) >> 16;
574 #ifdef DEBUG_BOARD_INIT
575 printf("Register parallel flash %d size " TARGET_FMT_lx
576 " at offset %08lx addr " TARGET_FMT_lx
" '%s'\n",
577 fl_idx
, bios_size
, bios_offset
, (target_ulong
)0xfc000000,
578 bdrv_get_device_name(dinfo
->bdrv
));
580 bios_offset
= qemu_ram_alloc(bios_size
);
581 pflash_cfi02_register(0xfc000000, bios_offset
,
582 dinfo
->bdrv
, 65536, fl_sectors
, 1,
583 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
587 /* Register CLPD & LCD display */
588 #ifdef DEBUG_BOARD_INIT
589 printf("%s: register CPLD\n", __func__
);
591 taihu_cpld_init(0x50100000);
593 linux_boot
= (kernel_filename
!= NULL
);
595 #ifdef DEBUG_BOARD_INIT
596 printf("%s: load kernel\n", __func__
);
598 kernel_base
= KERNEL_LOAD_ADDR
;
599 /* now we can load the kernel */
600 kernel_size
= load_image_targphys(kernel_filename
, kernel_base
,
601 ram_size
- kernel_base
);
602 if (kernel_size
< 0) {
603 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
608 if (initrd_filename
) {
609 initrd_base
= INITRD_LOAD_ADDR
;
610 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
611 ram_size
- initrd_base
);
612 if (initrd_size
< 0) {
614 "qemu: could not load initial ram disk '%s'\n",
628 #ifdef DEBUG_BOARD_INIT
629 printf("%s: Done\n", __func__
);
633 static QEMUMachine taihu_machine
= {
636 .init
= taihu_405ep_init
,
639 static void ppc405_machine_init(void)
641 qemu_register_machine(&ref405ep_machine
);
642 qemu_register_machine(&taihu_machine
);
645 machine_init(ppc405_machine_init
);