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
34 #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 *ref405ep_fpga_read[] = {
139 &ref405ep_fpga_readb,
140 &ref405ep_fpga_readw,
141 &ref405ep_fpga_readl,
144 static CPUWriteMemoryFunc *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(0, ref405ep_fpga_read,
166 ref405ep_fpga_write, fpga);
167 cpu_register_physical_memory(base, 0x00000100, fpga_memory);
168 ref405ep_fpga_reset(fpga);
169 qemu_register_reset(&ref405ep_fpga_reset, fpga);
172 static void ref405ep_init (ram_addr_t ram_size, int vga_ram_size,
173 const char *boot_device,
174 const char *kernel_filename,
175 const char *kernel_cmdline,
176 const char *initrd_filename,
177 const char *cpu_model)
183 ram_addr_t sram_offset, bios_offset, bdloc;
184 target_phys_addr_t ram_bases[2], ram_sizes[2];
185 target_ulong sram_size, bios_size;
187 //static int phy_addr = 1;
188 target_ulong kernel_base, kernel_size, initrd_base, initrd_size;
190 int fl_idx, fl_sectors, len;
191 int ppc_boot_device = boot_device[0];
195 ram_bases[0] = qemu_ram_alloc(0x08000000);
196 ram_sizes[0] = 0x08000000;
197 ram_bases[1] = 0x00000000;
198 ram_sizes[1] = 0x00000000;
199 ram_size = 128 * 1024 * 1024;
200 #ifdef DEBUG_BOARD_INIT
201 printf("%s: register cpu\n", __func__);
203 env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic,
204 kernel_filename == NULL ? 0 : 1);
206 sram_size = 512 * 1024;
207 sram_offset = qemu_ram_alloc(sram_size);
208 #ifdef DEBUG_BOARD_INIT
209 printf("%s: register SRAM at offset %08lx\n", __func__, sram_offset);
211 cpu_register_physical_memory(0xFFF00000, sram_size,
212 sram_offset | IO_MEM_RAM);
213 /* allocate and load BIOS */
214 #ifdef DEBUG_BOARD_INIT
215 printf("%s: register BIOS\n", __func__);
218 #ifdef USE_FLASH_BIOS
219 index = drive_get_index(IF_PFLASH, 0, fl_idx);
221 bios_size = bdrv_getlength(drives_table[index].bdrv);
222 bios_offset = qemu_ram_alloc(bios_size);
223 fl_sectors = (bios_size + 65535) >> 16;
224 #ifdef DEBUG_BOARD_INIT
225 printf("Register parallel flash %d size " ADDRX " at offset %08lx "
226 " addr " ADDRX " '%s' %d\n",
227 fl_idx, bios_size, bios_offset, -bios_size,
228 bdrv_get_device_name(drives_table[index].bdrv), fl_sectors);
230 pflash_cfi02_register((uint32_t)(-bios_size), bios_offset,
231 drives_table[index].bdrv, 65536, fl_sectors, 1,
232 2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
237 #ifdef DEBUG_BOARD_INIT
238 printf("Load BIOS from file\n");
240 if (bios_name == NULL)
241 bios_name = BIOS_FILENAME;
242 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
243 bios_offset = qemu_ram_alloc(BIOS_SIZE);
244 bios_size = load_image(buf, qemu_get_ram_ptr(bios_offset));
245 if (bios_size < 0 || bios_size > BIOS_SIZE) {
246 fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", buf);
249 bios_size = (bios_size + 0xfff) & ~0xfff;
250 cpu_register_physical_memory((uint32_t)(-bios_size),
251 bios_size, bios_offset | IO_MEM_ROM);
254 #ifdef DEBUG_BOARD_INIT
255 printf("%s: register FPGA\n", __func__);
257 ref405ep_fpga_init(0xF0300000);
259 #ifdef DEBUG_BOARD_INIT
260 printf("%s: register NVRAM\n", __func__);
262 m48t59_init(NULL, 0xF0000000, 0, 8192, 8);
264 linux_boot = (kernel_filename != NULL);
266 #ifdef DEBUG_BOARD_INIT
267 printf("%s: load kernel\n", __func__);
269 memset(&bd, 0, sizeof(bd));
270 bd.bi_memstart = 0x00000000;
271 bd.bi_memsize = ram_size;
272 bd.bi_flashstart = -bios_size;
273 bd.bi_flashsize = -bios_size;
274 bd.bi_flashoffset = 0;
275 bd.bi_sramstart = 0xFFF00000;
276 bd.bi_sramsize = sram_size;
278 bd.bi_intfreq = 133333333;
279 bd.bi_busfreq = 33333333;
280 bd.bi_baudrate = 115200;
281 bd.bi_s_version[0] = 'Q';
282 bd.bi_s_version[1] = 'M';
283 bd.bi_s_version[2] = 'U';
284 bd.bi_s_version[3] = '\0';
285 bd.bi_r_version[0] = 'Q';
286 bd.bi_r_version[1] = 'E';
287 bd.bi_r_version[2] = 'M';
288 bd.bi_r_version[3] = 'U';
289 bd.bi_r_version[4] = '\0';
290 bd.bi_procfreq = 133333333;
291 bd.bi_plb_busfreq = 33333333;
292 bd.bi_pci_busfreq = 33333333;
293 bd.bi_opbfreq = 33333333;
294 bdloc = ppc405_set_bootinfo(env, &bd, 0x00000001);
296 kernel_base = KERNEL_LOAD_ADDR;
297 /* now we can load the kernel */
298 kernel_size = load_image_targphys(kernel_filename, kernel_base,
299 ram_size - kernel_base);
300 if (kernel_size < 0) {
301 fprintf(stderr, "qemu: could not load kernel '%s'\n",
305 printf("Load kernel size " TARGET_FMT_ld " at " TARGET_FMT_lx,
306 kernel_size, kernel_base);
308 if (initrd_filename) {
309 initrd_base = INITRD_LOAD_ADDR;
310 initrd_size = load_image_targphys(initrd_filename, initrd_base,
311 ram_size - initrd_base);
312 if (initrd_size < 0) {
313 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
321 env->gpr[4] = initrd_base;
322 env->gpr[5] = initrd_size;
323 ppc_boot_device = 'm';
324 if (kernel_cmdline != NULL) {
325 len = strlen(kernel_cmdline);
326 bdloc -= ((len + 255) & ~255);
327 cpu_physical_memory_write(bdloc, (void *)kernel_cmdline, len + 1);
329 env->gpr[7] = bdloc + len;
334 env->nip = KERNEL_LOAD_ADDR;
342 #ifdef DEBUG_BOARD_INIT
343 printf("%s: Done\n", __func__);
345 printf("bdloc %016lx\n", (unsigned long)bdloc);
348 QEMUMachine ref405ep_machine = {
351 .init = ref405ep_init,
352 .ram_require = (128 * 1024 * 1024 + 4096 + 512 * 1024 + BIOS_SIZE) | RAMSIZE_FIXED,
355 /*****************************************************************************/
356 /* AMCC Taihu evaluation board */
357 /* - PowerPC 405EP processor
358 * - SDRAM 128 MB at 0x00000000
359 * - Boot flash 2 MB at 0xFFE00000
360 * - Application flash 32 MB at 0xFC000000
363 * - 1 USB 1.1 device 0x50000000
364 * - 1 LCD display 0x50100000
365 * - 1 CPLD 0x50100000
367 * - 1 I2C thermal sensor
369 * - bit-bang SPI port using GPIOs
370 * - 1 EBC interface connector 0 0x50200000
371 * - 1 cardbus controller + expansion slot.
372 * - 1 PCI expansion slot.
374 typedef struct taihu_cpld_t taihu_cpld_t;
375 struct taihu_cpld_t {
380 static uint32_t taihu_cpld_readb (void *opaque, target_phys_addr_t addr)
401 static void taihu_cpld_writeb (void *opaque,
402 target_phys_addr_t addr, uint32_t value)
419 static uint32_t taihu_cpld_readw (void *opaque, target_phys_addr_t addr)
423 ret = taihu_cpld_readb(opaque, addr) << 8;
424 ret |= taihu_cpld_readb(opaque, addr + 1);
429 static void taihu_cpld_writew (void *opaque,
430 target_phys_addr_t addr, uint32_t value)
432 taihu_cpld_writeb(opaque, addr, (value >> 8) & 0xFF);
433 taihu_cpld_writeb(opaque, addr + 1, value & 0xFF);
436 static uint32_t taihu_cpld_readl (void *opaque, target_phys_addr_t addr)
440 ret = taihu_cpld_readb(opaque, addr) << 24;
441 ret |= taihu_cpld_readb(opaque, addr + 1) << 16;
442 ret |= taihu_cpld_readb(opaque, addr + 2) << 8;
443 ret |= taihu_cpld_readb(opaque, addr + 3);
448 static void taihu_cpld_writel (void *opaque,
449 target_phys_addr_t addr, uint32_t value)
451 taihu_cpld_writel(opaque, addr, (value >> 24) & 0xFF);
452 taihu_cpld_writel(opaque, addr + 1, (value >> 16) & 0xFF);
453 taihu_cpld_writel(opaque, addr + 2, (value >> 8) & 0xFF);
454 taihu_cpld_writeb(opaque, addr + 3, value & 0xFF);
457 static CPUReadMemoryFunc *taihu_cpld_read[] = {
463 static CPUWriteMemoryFunc *taihu_cpld_write[] = {
469 static void taihu_cpld_reset (void *opaque)
478 static void taihu_cpld_init (uint32_t base)
483 cpld = qemu_mallocz(sizeof(taihu_cpld_t));
484 cpld_memory = cpu_register_io_memory(0, taihu_cpld_read,
485 taihu_cpld_write, cpld);
486 cpu_register_physical_memory(base, 0x00000100, cpld_memory);
487 taihu_cpld_reset(cpld);
488 qemu_register_reset(&taihu_cpld_reset, cpld);
491 static void taihu_405ep_init(ram_addr_t ram_size, int vga_ram_size,
492 const char *boot_device,
493 const char *kernel_filename,
494 const char *kernel_cmdline,
495 const char *initrd_filename,
496 const char *cpu_model)
501 ram_addr_t bios_offset;
502 target_phys_addr_t ram_bases[2], ram_sizes[2];
503 target_ulong bios_size;
504 target_ulong kernel_base, kernel_size, initrd_base, initrd_size;
506 int fl_idx, fl_sectors;
507 int ppc_boot_device = boot_device[0];
510 /* RAM is soldered to the board so the size cannot be changed */
511 ram_bases[0] = qemu_ram_alloc(0x04000000);
512 ram_sizes[0] = 0x04000000;
513 ram_bases[1] = qemu_ram_alloc(0x04000000);
514 ram_sizes[1] = 0x04000000;
515 ram_size = 0x08000000;
516 #ifdef DEBUG_BOARD_INIT
517 printf("%s: register cpu\n", __func__);
519 env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic,
520 kernel_filename == NULL ? 0 : 1);
521 /* allocate and load BIOS */
522 #ifdef DEBUG_BOARD_INIT
523 printf("%s: register BIOS\n", __func__);
526 #if defined(USE_FLASH_BIOS)
527 index = drive_get_index(IF_PFLASH, 0, fl_idx);
529 bios_size = bdrv_getlength(drives_table[index].bdrv);
530 /* XXX: should check that size is 2MB */
531 // bios_size = 2 * 1024 * 1024;
532 fl_sectors = (bios_size + 65535) >> 16;
533 bios_offset = qemu_ram_alloc(bios_size);
534 #ifdef DEBUG_BOARD_INIT
535 printf("Register parallel flash %d size " ADDRX " at offset %08lx "
536 " addr " ADDRX " '%s' %d\n",
537 fl_idx, bios_size, bios_offset, -bios_size,
538 bdrv_get_device_name(drives_table[index].bdrv), fl_sectors);
540 pflash_cfi02_register((uint32_t)(-bios_size), bios_offset,
541 drives_table[index].bdrv, 65536, fl_sectors, 1,
542 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
547 #ifdef DEBUG_BOARD_INIT
548 printf("Load BIOS from file\n");
550 if (bios_name == NULL)
551 bios_name = BIOS_FILENAME;
552 bios_offset = qemu_ram_alloc(BIOS_SIZE);
553 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
554 bios_size = load_image(buf, qemu_get_ram_ptr(bios_offset));
555 if (bios_size < 0 || bios_size > BIOS_SIZE) {
556 fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", buf);
559 bios_size = (bios_size + 0xfff) & ~0xfff;
560 cpu_register_physical_memory((uint32_t)(-bios_size),
561 bios_size, bios_offset | IO_MEM_ROM);
563 /* Register Linux flash */
564 index = drive_get_index(IF_PFLASH, 0, fl_idx);
566 bios_size = bdrv_getlength(drives_table[index].bdrv);
567 /* XXX: should check that size is 32MB */
568 bios_size = 32 * 1024 * 1024;
569 fl_sectors = (bios_size + 65535) >> 16;
570 #ifdef DEBUG_BOARD_INIT
571 printf("Register parallel flash %d size " ADDRX " at offset %08lx "
572 " addr " ADDRX " '%s'\n",
573 fl_idx, bios_size, bios_offset, (target_ulong)0xfc000000,
574 bdrv_get_device_name(drives_table[index].bdrv));
576 bios_offset = qemu_ram_alloc(bios_size);
577 pflash_cfi02_register(0xfc000000, bios_offset,
578 drives_table[index].bdrv, 65536, fl_sectors, 1,
579 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
582 /* Register CLPD & LCD display */
583 #ifdef DEBUG_BOARD_INIT
584 printf("%s: register CPLD\n", __func__);
586 taihu_cpld_init(0x50100000);
588 linux_boot = (kernel_filename != NULL);
590 #ifdef DEBUG_BOARD_INIT
591 printf("%s: load kernel\n", __func__);
593 kernel_base = KERNEL_LOAD_ADDR;
594 /* now we can load the kernel */
595 kernel_size = load_image_targphys(kernel_filename, kernel_base,
596 ram_size - kernel_base);
597 if (kernel_size < 0) {
598 fprintf(stderr, "qemu: could not load kernel '%s'\n",
603 if (initrd_filename) {
604 initrd_base = INITRD_LOAD_ADDR;
605 initrd_size = load_image_targphys(initrd_filename, initrd_base,
606 ram_size - initrd_base);
607 if (initrd_size < 0) {
609 "qemu: could not load initial ram disk '%s'\n",
617 ppc_boot_device = 'm';
624 #ifdef DEBUG_BOARD_INIT
625 printf("%s: Done\n", __func__);
629 QEMUMachine taihu_machine = {
633 (128 * 1024 * 1024 + 4096 + BIOS_SIZE + 32 * 1024 * 1024) | RAMSIZE_FIXED,