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 /*****************************************************************************/
52 /* PPC405EP reference board (IBM) */
53 /* Standalone board with:
55 * - SDRAM (0x00000000)
56 * - Flash (0xFFF80000)
58 * - NVRAM (0xF0000000)
61 typedef struct ref405ep_fpga_t ref405ep_fpga_t
;
62 struct ref405ep_fpga_t
{
67 static uint64_t ref405ep_fpga_readb(void *opaque
, hwaddr addr
, unsigned size
)
69 ref405ep_fpga_t
*fpga
;
88 static void ref405ep_fpga_writeb(void *opaque
, hwaddr addr
, uint64_t value
,
91 ref405ep_fpga_t
*fpga
;
106 static const MemoryRegionOps ref405ep_fpga_ops
= {
107 .read
= ref405ep_fpga_readb
,
108 .write
= ref405ep_fpga_writeb
,
109 .impl
.min_access_size
= 1,
110 .impl
.max_access_size
= 1,
111 .valid
.min_access_size
= 1,
112 .valid
.max_access_size
= 4,
113 .endianness
= DEVICE_BIG_ENDIAN
,
116 static void ref405ep_fpga_reset (void *opaque
)
118 ref405ep_fpga_t
*fpga
;
125 static void ref405ep_fpga_init(MemoryRegion
*sysmem
, uint32_t base
)
127 ref405ep_fpga_t
*fpga
;
128 MemoryRegion
*fpga_memory
= g_new(MemoryRegion
, 1);
130 fpga
= g_malloc0(sizeof(ref405ep_fpga_t
));
131 memory_region_init_io(fpga_memory
, NULL
, &ref405ep_fpga_ops
, fpga
,
133 memory_region_add_subregion(sysmem
, base
, fpga_memory
);
134 qemu_register_reset(&ref405ep_fpga_reset
, fpga
);
137 static void ref405ep_init(MachineState
*machine
)
139 ram_addr_t ram_size
= machine
->ram_size
;
140 const char *kernel_filename
= machine
->kernel_filename
;
141 const char *kernel_cmdline
= machine
->kernel_cmdline
;
142 const char *initrd_filename
= machine
->initrd_filename
;
148 MemoryRegion
*sram
= g_new(MemoryRegion
, 1);
150 MemoryRegion
*ram_memories
= g_new(MemoryRegion
, 2);
151 hwaddr ram_bases
[2], ram_sizes
[2];
152 target_ulong sram_size
;
155 //static int phy_addr = 1;
156 target_ulong kernel_base
, initrd_base
;
157 long kernel_size
, initrd_size
;
161 MemoryRegion
*sysmem
= get_system_memory();
164 memory_region_allocate_system_memory(&ram_memories
[0], NULL
, "ef405ep.ram",
167 ram_sizes
[0] = 0x08000000;
168 memory_region_init(&ram_memories
[1], NULL
, "ef405ep.ram1", 0);
169 ram_bases
[1] = 0x00000000;
170 ram_sizes
[1] = 0x00000000;
171 ram_size
= 128 * MiB
;
172 env
= ppc405ep_init(sysmem
, ram_memories
, ram_bases
, ram_sizes
,
173 33333333, &pic
, kernel_filename
== NULL
? 0 : 1);
175 sram_size
= 512 * KiB
;
176 memory_region_init_ram(sram
, NULL
, "ef405ep.sram", sram_size
,
178 memory_region_add_subregion(sysmem
, 0xFFF00000, sram
);
179 /* allocate and load BIOS */
180 #ifdef USE_FLASH_BIOS
181 dinfo
= drive_get(IF_PFLASH
, 0, 0);
184 pflash_cfi02_register((uint32_t)(-bios_size
),
185 "ef405ep.bios", bios_size
,
186 dinfo
? blk_by_legacy_dinfo(dinfo
) : NULL
,
188 2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
193 bios
= g_new(MemoryRegion
, 1);
194 memory_region_init_ram(bios
, NULL
, "ef405ep.bios", BIOS_SIZE
,
197 if (bios_name
== NULL
)
198 bios_name
= BIOS_FILENAME
;
199 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
201 bios_size
= load_image_size(filename
,
202 memory_region_get_ram_ptr(bios
),
206 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
209 bios_size
= (bios_size
+ 0xfff) & ~0xfff;
210 memory_region_add_subregion(sysmem
, (uint32_t)(-bios_size
), bios
);
211 } else if (!qtest_enabled() || kernel_filename
!= NULL
) {
212 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
215 /* Avoid an uninitialized variable warning */
218 memory_region_set_readonly(bios
, true);
221 ref405ep_fpga_init(sysmem
, 0xF0300000);
223 m48t59_init(NULL
, 0xF0000000, 0, 8192, 1968, 8);
225 linux_boot
= (kernel_filename
!= NULL
);
227 memset(&bd
, 0, sizeof(bd
));
228 bd
.bi_memstart
= 0x00000000;
229 bd
.bi_memsize
= ram_size
;
230 bd
.bi_flashstart
= -bios_size
;
231 bd
.bi_flashsize
= -bios_size
;
232 bd
.bi_flashoffset
= 0;
233 bd
.bi_sramstart
= 0xFFF00000;
234 bd
.bi_sramsize
= sram_size
;
236 bd
.bi_intfreq
= 133333333;
237 bd
.bi_busfreq
= 33333333;
238 bd
.bi_baudrate
= 115200;
239 bd
.bi_s_version
[0] = 'Q';
240 bd
.bi_s_version
[1] = 'M';
241 bd
.bi_s_version
[2] = 'U';
242 bd
.bi_s_version
[3] = '\0';
243 bd
.bi_r_version
[0] = 'Q';
244 bd
.bi_r_version
[1] = 'E';
245 bd
.bi_r_version
[2] = 'M';
246 bd
.bi_r_version
[3] = 'U';
247 bd
.bi_r_version
[4] = '\0';
248 bd
.bi_procfreq
= 133333333;
249 bd
.bi_plb_busfreq
= 33333333;
250 bd
.bi_pci_busfreq
= 33333333;
251 bd
.bi_opbfreq
= 33333333;
252 bdloc
= ppc405_set_bootinfo(env
, &bd
, 0x00000001);
254 kernel_base
= KERNEL_LOAD_ADDR
;
255 /* now we can load the kernel */
256 kernel_size
= load_image_targphys(kernel_filename
, kernel_base
,
257 ram_size
- kernel_base
);
258 if (kernel_size
< 0) {
259 error_report("could not load kernel '%s'", kernel_filename
);
262 printf("Load kernel size %ld at " TARGET_FMT_lx
,
263 kernel_size
, kernel_base
);
265 if (initrd_filename
) {
266 initrd_base
= INITRD_LOAD_ADDR
;
267 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
268 ram_size
- initrd_base
);
269 if (initrd_size
< 0) {
270 error_report("could not load initial ram disk '%s'",
278 env
->gpr
[4] = initrd_base
;
279 env
->gpr
[5] = initrd_size
;
280 if (kernel_cmdline
!= NULL
) {
281 len
= strlen(kernel_cmdline
);
282 bdloc
-= ((len
+ 255) & ~255);
283 cpu_physical_memory_write(bdloc
, kernel_cmdline
, len
+ 1);
285 env
->gpr
[7] = bdloc
+ len
;
290 env
->nip
= KERNEL_LOAD_ADDR
;
300 static void ref405ep_class_init(ObjectClass
*oc
, void *data
)
302 MachineClass
*mc
= MACHINE_CLASS(oc
);
304 mc
->desc
= "ref405ep";
305 mc
->init
= ref405ep_init
;
308 static const TypeInfo ref405ep_type
= {
309 .name
= MACHINE_TYPE_NAME("ref405ep"),
310 .parent
= TYPE_MACHINE
,
311 .class_init
= ref405ep_class_init
,
314 /*****************************************************************************/
315 /* AMCC Taihu evaluation board */
316 /* - PowerPC 405EP processor
317 * - SDRAM 128 MB at 0x00000000
318 * - Boot flash 2 MB at 0xFFE00000
319 * - Application flash 32 MB at 0xFC000000
322 * - 1 USB 1.1 device 0x50000000
323 * - 1 LCD display 0x50100000
324 * - 1 CPLD 0x50100000
326 * - 1 I2C thermal sensor
328 * - bit-bang SPI port using GPIOs
329 * - 1 EBC interface connector 0 0x50200000
330 * - 1 cardbus controller + expansion slot.
331 * - 1 PCI expansion slot.
333 typedef struct taihu_cpld_t taihu_cpld_t
;
334 struct taihu_cpld_t
{
339 static uint64_t taihu_cpld_read(void *opaque
, hwaddr addr
, unsigned size
)
360 static void taihu_cpld_write(void *opaque
, hwaddr addr
,
361 uint64_t value
, unsigned size
)
378 static const MemoryRegionOps taihu_cpld_ops
= {
379 .read
= taihu_cpld_read
,
380 .write
= taihu_cpld_write
,
382 .min_access_size
= 1,
383 .max_access_size
= 1,
385 .endianness
= DEVICE_NATIVE_ENDIAN
,
388 static void taihu_cpld_reset (void *opaque
)
397 static void taihu_cpld_init(MemoryRegion
*sysmem
, uint32_t base
)
400 MemoryRegion
*cpld_memory
= g_new(MemoryRegion
, 1);
402 cpld
= g_malloc0(sizeof(taihu_cpld_t
));
403 memory_region_init_io(cpld_memory
, NULL
, &taihu_cpld_ops
, cpld
, "cpld", 0x100);
404 memory_region_add_subregion(sysmem
, base
, cpld_memory
);
405 qemu_register_reset(&taihu_cpld_reset
, cpld
);
408 static void taihu_405ep_init(MachineState
*machine
)
410 ram_addr_t ram_size
= machine
->ram_size
;
411 const char *kernel_filename
= machine
->kernel_filename
;
412 const char *initrd_filename
= machine
->initrd_filename
;
415 MemoryRegion
*sysmem
= get_system_memory();
417 MemoryRegion
*ram_memories
= g_new(MemoryRegion
, 2);
418 MemoryRegion
*ram
= g_malloc0(sizeof(*ram
));
419 hwaddr ram_bases
[2], ram_sizes
[2];
421 target_ulong kernel_base
, initrd_base
;
422 long kernel_size
, initrd_size
;
427 /* RAM is soldered to the board so the size cannot be changed */
428 ram_size
= 0x08000000;
429 memory_region_allocate_system_memory(ram
, NULL
, "taihu_405ep.ram",
433 ram_sizes
[0] = 0x04000000;
434 memory_region_init_alias(&ram_memories
[0], NULL
,
435 "taihu_405ep.ram-0", ram
, ram_bases
[0],
437 ram_bases
[1] = 0x04000000;
438 ram_sizes
[1] = 0x04000000;
439 memory_region_init_alias(&ram_memories
[1], NULL
,
440 "taihu_405ep.ram-1", ram
, ram_bases
[1],
442 ppc405ep_init(sysmem
, ram_memories
, ram_bases
, ram_sizes
,
443 33333333, &pic
, kernel_filename
== NULL
? 0 : 1);
444 /* allocate and load BIOS */
446 #if defined(USE_FLASH_BIOS)
447 dinfo
= drive_get(IF_PFLASH
, 0, fl_idx
);
450 pflash_cfi02_register(0xFFE00000,
451 "taihu_405ep.bios", bios_size
,
452 dinfo
? blk_by_legacy_dinfo(dinfo
) : NULL
,
454 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
460 if (bios_name
== NULL
)
461 bios_name
= BIOS_FILENAME
;
462 bios
= g_new(MemoryRegion
, 1);
463 memory_region_init_ram(bios
, NULL
, "taihu_405ep.bios", BIOS_SIZE
,
465 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
467 bios_size
= load_image_size(filename
,
468 memory_region_get_ram_ptr(bios
),
472 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
475 bios_size
= (bios_size
+ 0xfff) & ~0xfff;
476 memory_region_add_subregion(sysmem
, (uint32_t)(-bios_size
), bios
);
477 } else if (!qtest_enabled()) {
478 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
481 memory_region_set_readonly(bios
, true);
483 /* Register Linux flash */
484 dinfo
= drive_get(IF_PFLASH
, 0, fl_idx
);
486 bios_size
= 32 * MiB
;
487 pflash_cfi02_register(0xfc000000, "taihu_405ep.flash", bios_size
,
488 dinfo
? blk_by_legacy_dinfo(dinfo
) : NULL
,
490 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
494 /* Register CLPD & LCD display */
495 taihu_cpld_init(sysmem
, 0x50100000);
497 linux_boot
= (kernel_filename
!= NULL
);
499 kernel_base
= KERNEL_LOAD_ADDR
;
500 /* now we can load the kernel */
501 kernel_size
= load_image_targphys(kernel_filename
, kernel_base
,
502 ram_size
- kernel_base
);
503 if (kernel_size
< 0) {
504 error_report("could not load kernel '%s'", kernel_filename
);
508 if (initrd_filename
) {
509 initrd_base
= INITRD_LOAD_ADDR
;
510 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
511 ram_size
- initrd_base
);
512 if (initrd_size
< 0) {
513 error_report("could not load initial ram disk '%s'",
529 static void taihu_class_init(ObjectClass
*oc
, void *data
)
531 MachineClass
*mc
= MACHINE_CLASS(oc
);
534 mc
->init
= taihu_405ep_init
;
537 static const TypeInfo taihu_type
= {
538 .name
= MACHINE_TYPE_NAME("taihu"),
539 .parent
= TYPE_MACHINE
,
540 .class_init
= taihu_class_init
,
543 static void ppc405_machine_init(void)
545 type_register_static(&ref405ep_type
);
546 type_register_static(&taihu_type
);
549 type_init(ppc405_machine_init
)