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
25 #include "qemu/osdep.h"
26 #include "qemu/units.h"
27 #include "qapi/error.h"
28 #include "qemu-common.h"
30 #include "hw/ppc/ppc.h"
32 #include "hw/rtc/m48t59.h"
33 #include "hw/block/flash.h"
34 #include "sysemu/sysemu.h"
35 #include "sysemu/qtest.h"
36 #include "sysemu/reset.h"
37 #include "sysemu/block-backend.h"
38 #include "hw/boards.h"
40 #include "qemu/error-report.h"
41 #include "hw/loader.h"
42 #include "exec/address-spaces.h"
43 #include "qemu/cutils.h"
45 #define BIOS_FILENAME "ppc405_rom.bin"
46 #define BIOS_SIZE (2 * MiB)
48 #define KERNEL_LOAD_ADDR 0x00000000
49 #define INITRD_LOAD_ADDR 0x01800000
51 #define USE_FLASH_BIOS
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 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
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_new(MemoryRegion
, 2);
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
;
163 MemoryRegion
*sysmem
= get_system_memory();
165 if (machine
->ram_size
!= mc
->default_ram_size
) {
166 char *sz
= size_to_str(mc
->default_ram_size
);
167 error_report("Invalid RAM size, should be %s", sz
);
173 memory_region_init_alias(&ram_memories
[0], NULL
, "ef405ep.ram.alias",
174 machine
->ram
, 0, machine
->ram_size
);
176 ram_sizes
[0] = machine
->ram_size
;
177 memory_region_init(&ram_memories
[1], NULL
, "ef405ep.ram1", 0);
178 ram_bases
[1] = 0x00000000;
179 ram_sizes
[1] = 0x00000000;
180 env
= ppc405ep_init(sysmem
, ram_memories
, ram_bases
, ram_sizes
,
181 33333333, &pic
, kernel_filename
== NULL
? 0 : 1);
183 sram_size
= 512 * KiB
;
184 memory_region_init_ram(sram
, NULL
, "ef405ep.sram", sram_size
,
186 memory_region_add_subregion(sysmem
, 0xFFF00000, sram
);
187 /* allocate and load BIOS */
188 #ifdef USE_FLASH_BIOS
189 dinfo
= drive_get(IF_PFLASH
, 0, 0);
192 pflash_cfi02_register((uint32_t)(-bios_size
),
193 "ef405ep.bios", bios_size
,
194 blk_by_legacy_dinfo(dinfo
),
196 2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
201 bios
= g_new(MemoryRegion
, 1);
202 memory_region_init_rom(bios
, NULL
, "ef405ep.bios", BIOS_SIZE
,
205 if (bios_name
== NULL
)
206 bios_name
= BIOS_FILENAME
;
207 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
209 bios_size
= load_image_size(filename
,
210 memory_region_get_ram_ptr(bios
),
214 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
217 bios_size
= (bios_size
+ 0xfff) & ~0xfff;
218 memory_region_add_subregion(sysmem
, (uint32_t)(-bios_size
), bios
);
219 } else if (!qtest_enabled() || kernel_filename
!= NULL
) {
220 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
223 /* Avoid an uninitialized variable warning */
228 ref405ep_fpga_init(sysmem
, 0xF0300000);
230 m48t59_init(NULL
, 0xF0000000, 0, 8192, 1968, 8);
232 linux_boot
= (kernel_filename
!= NULL
);
234 memset(&bd
, 0, sizeof(bd
));
235 bd
.bi_memstart
= 0x00000000;
236 bd
.bi_memsize
= machine
->ram_size
;
237 bd
.bi_flashstart
= -bios_size
;
238 bd
.bi_flashsize
= -bios_size
;
239 bd
.bi_flashoffset
= 0;
240 bd
.bi_sramstart
= 0xFFF00000;
241 bd
.bi_sramsize
= sram_size
;
243 bd
.bi_intfreq
= 133333333;
244 bd
.bi_busfreq
= 33333333;
245 bd
.bi_baudrate
= 115200;
246 bd
.bi_s_version
[0] = 'Q';
247 bd
.bi_s_version
[1] = 'M';
248 bd
.bi_s_version
[2] = 'U';
249 bd
.bi_s_version
[3] = '\0';
250 bd
.bi_r_version
[0] = 'Q';
251 bd
.bi_r_version
[1] = 'E';
252 bd
.bi_r_version
[2] = 'M';
253 bd
.bi_r_version
[3] = 'U';
254 bd
.bi_r_version
[4] = '\0';
255 bd
.bi_procfreq
= 133333333;
256 bd
.bi_plb_busfreq
= 33333333;
257 bd
.bi_pci_busfreq
= 33333333;
258 bd
.bi_opbfreq
= 33333333;
259 bdloc
= ppc405_set_bootinfo(env
, &bd
, 0x00000001);
261 kernel_base
= KERNEL_LOAD_ADDR
;
262 /* now we can load the kernel */
263 kernel_size
= load_image_targphys(kernel_filename
, kernel_base
,
264 machine
->ram_size
- kernel_base
);
265 if (kernel_size
< 0) {
266 error_report("could not load kernel '%s'", kernel_filename
);
269 printf("Load kernel size %ld at " TARGET_FMT_lx
,
270 kernel_size
, kernel_base
);
272 if (initrd_filename
) {
273 initrd_base
= INITRD_LOAD_ADDR
;
274 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
275 machine
->ram_size
- initrd_base
);
276 if (initrd_size
< 0) {
277 error_report("could not load initial ram disk '%s'",
285 env
->gpr
[4] = initrd_base
;
286 env
->gpr
[5] = initrd_size
;
287 if (kernel_cmdline
!= NULL
) {
288 len
= strlen(kernel_cmdline
);
289 bdloc
-= ((len
+ 255) & ~255);
290 cpu_physical_memory_write(bdloc
, kernel_cmdline
, len
+ 1);
292 env
->gpr
[7] = bdloc
+ len
;
297 env
->nip
= KERNEL_LOAD_ADDR
;
307 static void ref405ep_class_init(ObjectClass
*oc
, void *data
)
309 MachineClass
*mc
= MACHINE_CLASS(oc
);
311 mc
->desc
= "ref405ep";
312 mc
->init
= ref405ep_init
;
313 mc
->default_ram_size
= 0x08000000;
314 mc
->default_ram_id
= "ef405ep.ram";
317 static const TypeInfo ref405ep_type
= {
318 .name
= MACHINE_TYPE_NAME("ref405ep"),
319 .parent
= TYPE_MACHINE
,
320 .class_init
= ref405ep_class_init
,
323 /*****************************************************************************/
324 /* AMCC Taihu evaluation board */
325 /* - PowerPC 405EP processor
326 * - SDRAM 128 MB at 0x00000000
327 * - Boot flash 2 MB at 0xFFE00000
328 * - Application flash 32 MB at 0xFC000000
331 * - 1 USB 1.1 device 0x50000000
332 * - 1 LCD display 0x50100000
333 * - 1 CPLD 0x50100000
335 * - 1 I2C thermal sensor
337 * - bit-bang SPI port using GPIOs
338 * - 1 EBC interface connector 0 0x50200000
339 * - 1 cardbus controller + expansion slot.
340 * - 1 PCI expansion slot.
342 typedef struct taihu_cpld_t taihu_cpld_t
;
343 struct taihu_cpld_t
{
348 static uint64_t taihu_cpld_read(void *opaque
, hwaddr addr
, unsigned size
)
369 static void taihu_cpld_write(void *opaque
, hwaddr addr
,
370 uint64_t value
, unsigned size
)
387 static const MemoryRegionOps taihu_cpld_ops
= {
388 .read
= taihu_cpld_read
,
389 .write
= taihu_cpld_write
,
391 .min_access_size
= 1,
392 .max_access_size
= 1,
394 .endianness
= DEVICE_NATIVE_ENDIAN
,
397 static void taihu_cpld_reset (void *opaque
)
406 static void taihu_cpld_init(MemoryRegion
*sysmem
, uint32_t base
)
409 MemoryRegion
*cpld_memory
= g_new(MemoryRegion
, 1);
411 cpld
= g_malloc0(sizeof(taihu_cpld_t
));
412 memory_region_init_io(cpld_memory
, NULL
, &taihu_cpld_ops
, cpld
, "cpld", 0x100);
413 memory_region_add_subregion(sysmem
, base
, cpld_memory
);
414 qemu_register_reset(&taihu_cpld_reset
, cpld
);
417 static void taihu_405ep_init(MachineState
*machine
)
419 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
420 const char *kernel_filename
= machine
->kernel_filename
;
421 const char *initrd_filename
= machine
->initrd_filename
;
424 MemoryRegion
*sysmem
= get_system_memory();
426 MemoryRegion
*ram_memories
= g_new(MemoryRegion
, 2);
427 hwaddr ram_bases
[2], ram_sizes
[2];
429 target_ulong kernel_base
, initrd_base
;
430 long kernel_size
, initrd_size
;
435 if (machine
->ram_size
!= mc
->default_ram_size
) {
436 char *sz
= size_to_str(mc
->default_ram_size
);
437 error_report("Invalid RAM size, should be %s", sz
);
443 ram_sizes
[0] = 0x04000000;
444 memory_region_init_alias(&ram_memories
[0], NULL
,
445 "taihu_405ep.ram-0", machine
->ram
, ram_bases
[0],
447 ram_bases
[1] = 0x04000000;
448 ram_sizes
[1] = 0x04000000;
449 memory_region_init_alias(&ram_memories
[1], NULL
,
450 "taihu_405ep.ram-1", machine
->ram
, ram_bases
[1],
452 ppc405ep_init(sysmem
, ram_memories
, ram_bases
, ram_sizes
,
453 33333333, &pic
, kernel_filename
== NULL
? 0 : 1);
454 /* allocate and load BIOS */
456 #if defined(USE_FLASH_BIOS)
457 dinfo
= drive_get(IF_PFLASH
, 0, fl_idx
);
460 pflash_cfi02_register(0xFFE00000,
461 "taihu_405ep.bios", bios_size
,
462 blk_by_legacy_dinfo(dinfo
),
464 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
470 if (bios_name
== NULL
)
471 bios_name
= BIOS_FILENAME
;
472 bios
= g_new(MemoryRegion
, 1);
473 memory_region_init_rom(bios
, NULL
, "taihu_405ep.bios", BIOS_SIZE
,
475 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
477 bios_size
= load_image_size(filename
,
478 memory_region_get_ram_ptr(bios
),
482 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
485 bios_size
= (bios_size
+ 0xfff) & ~0xfff;
486 memory_region_add_subregion(sysmem
, (uint32_t)(-bios_size
), bios
);
487 } else if (!qtest_enabled()) {
488 error_report("Could not load PowerPC BIOS '%s'", bios_name
);
492 /* Register Linux flash */
493 dinfo
= drive_get(IF_PFLASH
, 0, fl_idx
);
495 bios_size
= 32 * MiB
;
496 pflash_cfi02_register(0xfc000000, "taihu_405ep.flash", bios_size
,
497 blk_by_legacy_dinfo(dinfo
),
499 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
503 /* Register CLPD & LCD display */
504 taihu_cpld_init(sysmem
, 0x50100000);
506 linux_boot
= (kernel_filename
!= NULL
);
508 kernel_base
= KERNEL_LOAD_ADDR
;
509 /* now we can load the kernel */
510 kernel_size
= load_image_targphys(kernel_filename
, kernel_base
,
511 machine
->ram_size
- kernel_base
);
512 if (kernel_size
< 0) {
513 error_report("could not load kernel '%s'", kernel_filename
);
517 if (initrd_filename
) {
518 initrd_base
= INITRD_LOAD_ADDR
;
519 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
520 machine
->ram_size
- initrd_base
);
521 if (initrd_size
< 0) {
522 error_report("could not load initial ram disk '%s'",
538 static void taihu_class_init(ObjectClass
*oc
, void *data
)
540 MachineClass
*mc
= MACHINE_CLASS(oc
);
543 mc
->init
= taihu_405ep_init
;
544 mc
->default_ram_size
= 0x08000000;
545 mc
->default_ram_id
= "taihu_405ep.ram";
548 static const TypeInfo taihu_type
= {
549 .name
= MACHINE_TYPE_NAME("taihu"),
550 .parent
= TYPE_MACHINE
,
551 .class_init
= taihu_class_init
,
554 static void ppc405_machine_init(void)
556 type_register_static(&ref405ep_type
);
557 type_register_static(&taihu_type
);
560 type_init(ppc405_machine_init
)