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
24 #include "qemu/osdep.h"
25 #include "qemu/units.h"
26 #include "qapi/error.h"
27 #include "qemu-common.h"
30 #include "hw/ppc/ppc.h"
32 #include "hw/timer/m48t59.h"
33 #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"
39 #include "qemu/error-report.h"
40 #include "hw/loader.h"
41 #include "exec/address-spaces.h"
43 #define BIOS_FILENAME "ppc405_rom.bin"
44 #define BIOS_SIZE (2 * MiB)
46 #define KERNEL_LOAD_ADDR 0x00000000
47 #define INITRD_LOAD_ADDR 0x01800000
49 #define USE_FLASH_BIOS
51 //#define DEBUG_BOARD_INIT
53 /*****************************************************************************/
54 /* PPC405EP reference board (IBM) */
55 /* Standalone board with:
57 * - SDRAM (0x00000000)
58 * - Flash (0xFFF80000)
60 * - NVRAM (0xF0000000)
63 typedef struct ref405ep_fpga_t ref405ep_fpga_t
;
64 struct ref405ep_fpga_t
{
69 static uint64_t ref405ep_fpga_readb(void *opaque
, hwaddr addr
, unsigned size
)
71 ref405ep_fpga_t
*fpga
;
90 static void ref405ep_fpga_writeb(void *opaque
, hwaddr addr
, uint64_t value
,
93 ref405ep_fpga_t
*fpga
;
108 static const MemoryRegionOps ref405ep_fpga_ops
= {
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
,
118 static void ref405ep_fpga_reset (void *opaque
)
120 ref405ep_fpga_t
*fpga
;
127 static void ref405ep_fpga_init(MemoryRegion
*sysmem
, uint32_t base
)
129 ref405ep_fpga_t
*fpga
;
130 MemoryRegion
*fpga_memory
= g_new(MemoryRegion
, 1);
132 fpga
= g_malloc0(sizeof(ref405ep_fpga_t
));
133 memory_region_init_io(fpga_memory
, NULL
, &ref405ep_fpga_ops
, fpga
,
135 memory_region_add_subregion(sysmem
, base
, fpga_memory
);
136 qemu_register_reset(&ref405ep_fpga_reset
, fpga
);
139 static void ref405ep_init(MachineState
*machine
)
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
;
150 MemoryRegion
*sram
= g_new(MemoryRegion
, 1);
152 MemoryRegion
*ram_memories
= g_malloc(2 * sizeof(*ram_memories
));
153 hwaddr ram_bases
[2], ram_sizes
[2];
154 target_ulong sram_size
;
157 //static int phy_addr = 1;
158 target_ulong kernel_base
, initrd_base
;
159 long kernel_size
, initrd_size
;
161 int fl_idx
, fl_sectors
, len
;
163 MemoryRegion
*sysmem
= get_system_memory();
166 memory_region_allocate_system_memory(&ram_memories
[0], NULL
, "ef405ep.ram",
169 ram_sizes
[0] = 0x08000000;
170 memory_region_init(&ram_memories
[1], NULL
, "ef405ep.ram1", 0);
171 ram_bases
[1] = 0x00000000;
172 ram_sizes
[1] = 0x00000000;
173 ram_size
= 128 * MiB
;
174 #ifdef DEBUG_BOARD_INIT
175 printf("%s: register cpu\n", __func__
);
177 env
= ppc405ep_init(sysmem
, ram_memories
, ram_bases
, ram_sizes
,
178 33333333, &pic
, kernel_filename
== NULL
? 0 : 1);
180 sram_size
= 512 * KiB
;
181 memory_region_init_ram(sram
, NULL
, "ef405ep.sram", sram_size
,
183 memory_region_add_subregion(sysmem
, 0xFFF00000, sram
);
184 /* allocate and load BIOS */
185 #ifdef DEBUG_BOARD_INIT
186 printf("%s: register BIOS\n", __func__
);
189 #ifdef USE_FLASH_BIOS
190 dinfo
= drive_get(IF_PFLASH
, 0, fl_idx
);
192 BlockBackend
*blk
= blk_by_legacy_dinfo(dinfo
);
194 bios_size
= blk_getlength(blk
);
195 fl_sectors
= (bios_size
+ 65535) >> 16;
196 #ifdef DEBUG_BOARD_INIT
197 printf("Register parallel flash %d size %lx"
198 " at addr %lx '%s' %d\n",
199 fl_idx
, bios_size
, -bios_size
,
200 blk_name(blk
), fl_sectors
);
202 pflash_cfi02_register((uint32_t)(-bios_size
),
203 NULL
, "ef405ep.bios", bios_size
,
204 blk
, 65536, fl_sectors
, 1,
205 2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
211 #ifdef DEBUG_BOARD_INIT
212 printf("Load BIOS from file\n");
214 bios
= g_new(MemoryRegion
, 1);
215 memory_region_init_ram(bios
, NULL
, "ef405ep.bios", BIOS_SIZE
,
218 if (bios_name
== NULL
)
219 bios_name
= BIOS_FILENAME
;
220 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
222 bios_size
= load_image(filename
, memory_region_get_ram_ptr(bios
));
224 if (bios_size
< 0 || bios_size
> BIOS_SIZE
) {
225 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
228 bios_size
= (bios_size
+ 0xfff) & ~0xfff;
229 memory_region_add_subregion(sysmem
, (uint32_t)(-bios_size
), bios
);
230 } else if (!qtest_enabled() || kernel_filename
!= NULL
) {
231 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
234 /* Avoid an uninitialized variable warning */
237 memory_region_set_readonly(bios
, true);
240 #ifdef DEBUG_BOARD_INIT
241 printf("%s: register FPGA\n", __func__
);
243 ref405ep_fpga_init(sysmem
, 0xF0300000);
245 #ifdef DEBUG_BOARD_INIT
246 printf("%s: register NVRAM\n", __func__
);
248 m48t59_init(NULL
, 0xF0000000, 0, 8192, 1968, 8);
250 linux_boot
= (kernel_filename
!= NULL
);
252 #ifdef DEBUG_BOARD_INIT
253 printf("%s: load kernel\n", __func__
);
255 memset(&bd
, 0, sizeof(bd
));
256 bd
.bi_memstart
= 0x00000000;
257 bd
.bi_memsize
= ram_size
;
258 bd
.bi_flashstart
= -bios_size
;
259 bd
.bi_flashsize
= -bios_size
;
260 bd
.bi_flashoffset
= 0;
261 bd
.bi_sramstart
= 0xFFF00000;
262 bd
.bi_sramsize
= sram_size
;
264 bd
.bi_intfreq
= 133333333;
265 bd
.bi_busfreq
= 33333333;
266 bd
.bi_baudrate
= 115200;
267 bd
.bi_s_version
[0] = 'Q';
268 bd
.bi_s_version
[1] = 'M';
269 bd
.bi_s_version
[2] = 'U';
270 bd
.bi_s_version
[3] = '\0';
271 bd
.bi_r_version
[0] = 'Q';
272 bd
.bi_r_version
[1] = 'E';
273 bd
.bi_r_version
[2] = 'M';
274 bd
.bi_r_version
[3] = 'U';
275 bd
.bi_r_version
[4] = '\0';
276 bd
.bi_procfreq
= 133333333;
277 bd
.bi_plb_busfreq
= 33333333;
278 bd
.bi_pci_busfreq
= 33333333;
279 bd
.bi_opbfreq
= 33333333;
280 bdloc
= ppc405_set_bootinfo(env
, &bd
, 0x00000001);
282 kernel_base
= KERNEL_LOAD_ADDR
;
283 /* now we can load the kernel */
284 kernel_size
= load_image_targphys(kernel_filename
, kernel_base
,
285 ram_size
- kernel_base
);
286 if (kernel_size
< 0) {
287 error_report("could not load kernel '%s'", kernel_filename
);
290 printf("Load kernel size %ld at " TARGET_FMT_lx
,
291 kernel_size
, kernel_base
);
293 if (initrd_filename
) {
294 initrd_base
= INITRD_LOAD_ADDR
;
295 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
296 ram_size
- initrd_base
);
297 if (initrd_size
< 0) {
298 error_report("could not load initial ram disk '%s'",
306 env
->gpr
[4] = initrd_base
;
307 env
->gpr
[5] = initrd_size
;
308 if (kernel_cmdline
!= NULL
) {
309 len
= strlen(kernel_cmdline
);
310 bdloc
-= ((len
+ 255) & ~255);
311 cpu_physical_memory_write(bdloc
, kernel_cmdline
, len
+ 1);
313 env
->gpr
[7] = bdloc
+ len
;
318 env
->nip
= KERNEL_LOAD_ADDR
;
326 #ifdef DEBUG_BOARD_INIT
327 printf("bdloc " RAM_ADDR_FMT
"\n", bdloc
);
328 printf("%s: Done\n", __func__
);
332 static void ref405ep_class_init(ObjectClass
*oc
, void *data
)
334 MachineClass
*mc
= MACHINE_CLASS(oc
);
336 mc
->desc
= "ref405ep";
337 mc
->init
= ref405ep_init
;
340 static const TypeInfo ref405ep_type
= {
341 .name
= MACHINE_TYPE_NAME("ref405ep"),
342 .parent
= TYPE_MACHINE
,
343 .class_init
= ref405ep_class_init
,
346 /*****************************************************************************/
347 /* AMCC Taihu evaluation board */
348 /* - PowerPC 405EP processor
349 * - SDRAM 128 MB at 0x00000000
350 * - Boot flash 2 MB at 0xFFE00000
351 * - Application flash 32 MB at 0xFC000000
354 * - 1 USB 1.1 device 0x50000000
355 * - 1 LCD display 0x50100000
356 * - 1 CPLD 0x50100000
358 * - 1 I2C thermal sensor
360 * - bit-bang SPI port using GPIOs
361 * - 1 EBC interface connector 0 0x50200000
362 * - 1 cardbus controller + expansion slot.
363 * - 1 PCI expansion slot.
365 typedef struct taihu_cpld_t taihu_cpld_t
;
366 struct taihu_cpld_t
{
371 static uint64_t taihu_cpld_read(void *opaque
, hwaddr addr
, unsigned size
)
392 static void taihu_cpld_write(void *opaque
, hwaddr addr
,
393 uint64_t value
, unsigned size
)
410 static const MemoryRegionOps taihu_cpld_ops
= {
411 .read
= taihu_cpld_read
,
412 .write
= taihu_cpld_write
,
414 .min_access_size
= 1,
415 .max_access_size
= 1,
417 .endianness
= DEVICE_NATIVE_ENDIAN
,
420 static void taihu_cpld_reset (void *opaque
)
429 static void taihu_cpld_init(MemoryRegion
*sysmem
, uint32_t base
)
432 MemoryRegion
*cpld_memory
= g_new(MemoryRegion
, 1);
434 cpld
= g_malloc0(sizeof(taihu_cpld_t
));
435 memory_region_init_io(cpld_memory
, NULL
, &taihu_cpld_ops
, cpld
, "cpld", 0x100);
436 memory_region_add_subregion(sysmem
, base
, cpld_memory
);
437 qemu_register_reset(&taihu_cpld_reset
, cpld
);
440 static void taihu_405ep_init(MachineState
*machine
)
442 ram_addr_t ram_size
= machine
->ram_size
;
443 const char *kernel_filename
= machine
->kernel_filename
;
444 const char *initrd_filename
= machine
->initrd_filename
;
447 MemoryRegion
*sysmem
= get_system_memory();
449 MemoryRegion
*ram_memories
= g_malloc(2 * sizeof(*ram_memories
));
450 MemoryRegion
*ram
= g_malloc0(sizeof(*ram
));
451 hwaddr ram_bases
[2], ram_sizes
[2];
453 target_ulong kernel_base
, initrd_base
;
454 long kernel_size
, initrd_size
;
456 int fl_idx
, fl_sectors
;
459 /* RAM is soldered to the board so the size cannot be changed */
460 ram_size
= 0x08000000;
461 memory_region_allocate_system_memory(ram
, NULL
, "taihu_405ep.ram",
465 ram_sizes
[0] = 0x04000000;
466 memory_region_init_alias(&ram_memories
[0], NULL
,
467 "taihu_405ep.ram-0", ram
, ram_bases
[0],
469 ram_bases
[1] = 0x04000000;
470 ram_sizes
[1] = 0x04000000;
471 memory_region_init_alias(&ram_memories
[1], NULL
,
472 "taihu_405ep.ram-1", ram
, ram_bases
[1],
474 #ifdef DEBUG_BOARD_INIT
475 printf("%s: register cpu\n", __func__
);
477 ppc405ep_init(sysmem
, ram_memories
, ram_bases
, ram_sizes
,
478 33333333, &pic
, kernel_filename
== NULL
? 0 : 1);
479 /* allocate and load BIOS */
480 #ifdef DEBUG_BOARD_INIT
481 printf("%s: register BIOS\n", __func__
);
484 #if defined(USE_FLASH_BIOS)
485 dinfo
= drive_get(IF_PFLASH
, 0, fl_idx
);
487 BlockBackend
*blk
= blk_by_legacy_dinfo(dinfo
);
489 bios_size
= blk_getlength(blk
);
490 /* XXX: should check that size is 2MB */
491 // bios_size = 2 * 1024 * 1024;
492 fl_sectors
= (bios_size
+ 65535) >> 16;
493 #ifdef DEBUG_BOARD_INIT
494 printf("Register parallel flash %d size %lx"
495 " at addr %lx '%s' %d\n",
496 fl_idx
, bios_size
, -bios_size
,
497 blk_name(blk
), fl_sectors
);
499 pflash_cfi02_register((uint32_t)(-bios_size
),
500 NULL
, "taihu_405ep.bios", bios_size
,
501 blk
, 65536, fl_sectors
, 1,
502 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
508 #ifdef DEBUG_BOARD_INIT
509 printf("Load BIOS from file\n");
511 if (bios_name
== NULL
)
512 bios_name
= BIOS_FILENAME
;
513 bios
= g_new(MemoryRegion
, 1);
514 memory_region_init_ram(bios
, NULL
, "taihu_405ep.bios", BIOS_SIZE
,
516 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
518 bios_size
= load_image(filename
, memory_region_get_ram_ptr(bios
));
520 if (bios_size
< 0 || bios_size
> BIOS_SIZE
) {
521 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
524 bios_size
= (bios_size
+ 0xfff) & ~0xfff;
525 memory_region_add_subregion(sysmem
, (uint32_t)(-bios_size
), bios
);
526 } else if (!qtest_enabled()) {
527 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
530 memory_region_set_readonly(bios
, true);
532 /* Register Linux flash */
533 dinfo
= drive_get(IF_PFLASH
, 0, fl_idx
);
535 BlockBackend
*blk
= blk_by_legacy_dinfo(dinfo
);
537 bios_size
= blk_getlength(blk
);
538 /* XXX: should check that size is 32MB */
539 bios_size
= 32 * MiB
;
540 fl_sectors
= (bios_size
+ 65535) >> 16;
541 #ifdef DEBUG_BOARD_INIT
542 printf("Register parallel flash %d size %lx"
543 " at addr " TARGET_FMT_lx
" '%s'\n",
544 fl_idx
, bios_size
, (target_ulong
)0xfc000000,
547 pflash_cfi02_register(0xfc000000, NULL
, "taihu_405ep.flash", bios_size
,
548 blk
, 65536, fl_sectors
, 1,
549 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
553 /* Register CLPD & LCD display */
554 #ifdef DEBUG_BOARD_INIT
555 printf("%s: register CPLD\n", __func__
);
557 taihu_cpld_init(sysmem
, 0x50100000);
559 linux_boot
= (kernel_filename
!= NULL
);
561 #ifdef DEBUG_BOARD_INIT
562 printf("%s: load kernel\n", __func__
);
564 kernel_base
= KERNEL_LOAD_ADDR
;
565 /* now we can load the kernel */
566 kernel_size
= load_image_targphys(kernel_filename
, kernel_base
,
567 ram_size
- kernel_base
);
568 if (kernel_size
< 0) {
569 error_report("could not load kernel '%s'", kernel_filename
);
573 if (initrd_filename
) {
574 initrd_base
= INITRD_LOAD_ADDR
;
575 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
576 ram_size
- initrd_base
);
577 if (initrd_size
< 0) {
578 error_report("could not load initial ram disk '%s'",
592 #ifdef DEBUG_BOARD_INIT
593 printf("%s: Done\n", __func__
);
597 static void taihu_class_init(ObjectClass
*oc
, void *data
)
599 MachineClass
*mc
= MACHINE_CLASS(oc
);
602 mc
->init
= taihu_405ep_init
;
605 static const TypeInfo taihu_type
= {
606 .name
= MACHINE_TYPE_NAME("taihu"),
607 .parent
= TYPE_MACHINE
,
608 .class_init
= taihu_class_init
,
611 static void ppc405_machine_init(void)
613 type_register_static(&ref405ep_type
);
614 type_register_static(&taihu_type
);
617 type_init(ppc405_machine_init
)