2 * Xilinx Zynq Baseboard System emulation.
4 * Copyright (c) 2010 Xilinx.
5 * Copyright (c) 2012 Peter A.G. Crosthwaite (peter.croshtwaite@petalogix.com)
6 * Copyright (c) 2012 Petalogix Pty Ltd.
7 * Written by Haibing Ma
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "exec-memory.h"
29 #define NUM_SPI_FLASHES 4
31 #define FLASH_SIZE (64 * 1024 * 1024)
32 #define FLASH_SECTOR_SIZE (128 * 1024)
34 #define IRQ_OFFSET 32 /* pic interrupts start from index 32 */
36 static struct arm_boot_info zynq_binfo
= {};
38 static void gem_init(NICInfo
*nd
, uint32_t base
, qemu_irq irq
)
43 qemu_check_nic_model(nd
, "cadence_gem");
44 dev
= qdev_create(NULL
, "cadence_gem");
45 qdev_set_nic_properties(dev
, nd
);
46 qdev_init_nofail(dev
);
47 s
= sysbus_from_qdev(dev
);
48 sysbus_mmio_map(s
, 0, base
);
49 sysbus_connect_irq(s
, 0, irq
);
52 static inline void zynq_init_spi_flashes(uint32_t base_addr
, qemu_irq irq
)
59 dev
= qdev_create(NULL
, "xilinx,spips");
60 qdev_init_nofail(dev
);
61 busdev
= sysbus_from_qdev(dev
);
62 sysbus_mmio_map(busdev
, 0, base_addr
);
63 sysbus_connect_irq(busdev
, 0, irq
);
65 spi
= (SSIBus
*)qdev_get_child_bus(dev
, "spi");
67 for (i
= 0; i
< NUM_SPI_FLASHES
; ++i
) {
70 dev
= ssi_create_slave_no_init(spi
, "m25p80");
71 qdev_prop_set_string(dev
, "partname", "n25q128");
72 qdev_init_nofail(dev
);
74 cs_line
= qdev_get_gpio_in(dev
, 0);
75 sysbus_connect_irq(busdev
, i
+1, cs_line
);
80 static void zynq_init(ram_addr_t ram_size
, const char *boot_device
,
81 const char *kernel_filename
, const char *kernel_cmdline
,
82 const char *initrd_filename
, const char *cpu_model
)
85 MemoryRegion
*address_space_mem
= get_system_memory();
86 MemoryRegion
*ext_ram
= g_new(MemoryRegion
, 1);
87 MemoryRegion
*ocm_ram
= g_new(MemoryRegion
, 1);
97 cpu_model
= "cortex-a9";
100 cpu
= cpu_arm_init(cpu_model
);
102 fprintf(stderr
, "Unable to find CPU definition\n");
105 irqp
= arm_pic_init_cpu(cpu
);
106 cpu_irq
= irqp
[ARM_PIC_CPU_IRQ
];
109 if (ram_size
> 0x80000000) {
110 ram_size
= 0x80000000;
113 /* DDR remapped to address zero. */
114 memory_region_init_ram(ext_ram
, "zynq.ext_ram", ram_size
);
115 vmstate_register_ram_global(ext_ram
);
116 memory_region_add_subregion(address_space_mem
, 0, ext_ram
);
118 /* 256K of on-chip memory */
119 memory_region_init_ram(ocm_ram
, "zynq.ocm_ram", 256 << 10);
120 vmstate_register_ram_global(ocm_ram
);
121 memory_region_add_subregion(address_space_mem
, 0xFFFC0000, ocm_ram
);
123 DriveInfo
*dinfo
= drive_get(IF_PFLASH
, 0, 0);
126 pflash_cfi02_register(0xe2000000, NULL
, "zynq.pflash", FLASH_SIZE
,
127 dinfo
? dinfo
->bdrv
: NULL
, FLASH_SECTOR_SIZE
,
128 FLASH_SIZE
/FLASH_SECTOR_SIZE
, 1,
129 1, 0x0066, 0x0022, 0x0000, 0x0000, 0x0555, 0x2aa,
132 dev
= qdev_create(NULL
, "xilinx,zynq_slcr");
133 qdev_init_nofail(dev
);
134 sysbus_mmio_map(sysbus_from_qdev(dev
), 0, 0xF8000000);
136 dev
= qdev_create(NULL
, "a9mpcore_priv");
137 qdev_prop_set_uint32(dev
, "num-cpu", 1);
138 qdev_init_nofail(dev
);
139 busdev
= sysbus_from_qdev(dev
);
140 sysbus_mmio_map(busdev
, 0, 0xF8F00000);
141 sysbus_connect_irq(busdev
, 0, cpu_irq
);
143 for (n
= 0; n
< 64; n
++) {
144 pic
[n
] = qdev_get_gpio_in(dev
, n
);
147 zynq_init_spi_flashes(0xE0006000, pic
[58-IRQ_OFFSET
]);
148 zynq_init_spi_flashes(0xE0007000, pic
[81-IRQ_OFFSET
]);
150 sysbus_create_simple("cadence_uart", 0xE0000000, pic
[59-IRQ_OFFSET
]);
151 sysbus_create_simple("cadence_uart", 0xE0001000, pic
[82-IRQ_OFFSET
]);
153 sysbus_create_varargs("cadence_ttc", 0xF8001000,
154 pic
[42-IRQ_OFFSET
], pic
[43-IRQ_OFFSET
], pic
[44-IRQ_OFFSET
], NULL
);
155 sysbus_create_varargs("cadence_ttc", 0xF8002000,
156 pic
[69-IRQ_OFFSET
], pic
[70-IRQ_OFFSET
], pic
[71-IRQ_OFFSET
], NULL
);
158 for (n
= 0; n
< nb_nics
; n
++) {
161 gem_init(nd
, 0xE000B000, pic
[54-IRQ_OFFSET
]);
163 gem_init(nd
, 0xE000C000, pic
[77-IRQ_OFFSET
]);
167 zynq_binfo
.ram_size
= ram_size
;
168 zynq_binfo
.kernel_filename
= kernel_filename
;
169 zynq_binfo
.kernel_cmdline
= kernel_cmdline
;
170 zynq_binfo
.initrd_filename
= initrd_filename
;
171 zynq_binfo
.nb_cpus
= 1;
172 zynq_binfo
.board_id
= 0xd32;
173 zynq_binfo
.loader_start
= 0;
174 arm_load_kernel(arm_env_get_cpu(first_cpu
), &zynq_binfo
);
177 static QEMUMachine zynq_machine
= {
178 .name
= "xilinx-zynq-a9",
179 .desc
= "Xilinx Zynq Platform Baseboard for Cortex-A9",
186 static void zynq_machine_init(void)
188 qemu_register_machine(&zynq_machine
);
191 machine_init(zynq_machine_init
);