Merge remote-tracking branch 'kraxel/testdev.1' into staging
[qemu.git] / hw / exynos4210.c
bloba7b84d61a0993e9a82e378ca7ef1bd636b4c9e83
1 /*
2 * Samsung exynos4210 SoC emulation
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 * Maksim Kozlov <m.kozlov@samsung.com>
6 * Evgeny Voevodin <e.voevodin@samsung.com>
7 * Igor Mitsyanko <i.mitsyanko@samsung.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see <http://www.gnu.org/licenses/>.
24 #include "boards.h"
25 #include "sysemu/sysemu.h"
26 #include "sysbus.h"
27 #include "arm-misc.h"
28 #include "loader.h"
29 #include "exynos4210.h"
31 #define EXYNOS4210_CHIPID_ADDR 0x10000000
33 /* PWM */
34 #define EXYNOS4210_PWM_BASE_ADDR 0x139D0000
36 /* RTC */
37 #define EXYNOS4210_RTC_BASE_ADDR 0x10070000
39 /* MCT */
40 #define EXYNOS4210_MCT_BASE_ADDR 0x10050000
42 /* I2C */
43 #define EXYNOS4210_I2C_SHIFT 0x00010000
44 #define EXYNOS4210_I2C_BASE_ADDR 0x13860000
45 /* Interrupt Group of External Interrupt Combiner for I2C */
46 #define EXYNOS4210_I2C_INTG 27
47 #define EXYNOS4210_HDMI_INTG 16
49 /* UART's definitions */
50 #define EXYNOS4210_UART0_BASE_ADDR 0x13800000
51 #define EXYNOS4210_UART1_BASE_ADDR 0x13810000
52 #define EXYNOS4210_UART2_BASE_ADDR 0x13820000
53 #define EXYNOS4210_UART3_BASE_ADDR 0x13830000
54 #define EXYNOS4210_UART0_FIFO_SIZE 256
55 #define EXYNOS4210_UART1_FIFO_SIZE 64
56 #define EXYNOS4210_UART2_FIFO_SIZE 16
57 #define EXYNOS4210_UART3_FIFO_SIZE 16
58 /* Interrupt Group of External Interrupt Combiner for UART */
59 #define EXYNOS4210_UART_INT_GRP 26
61 /* External GIC */
62 #define EXYNOS4210_EXT_GIC_CPU_BASE_ADDR 0x10480000
63 #define EXYNOS4210_EXT_GIC_DIST_BASE_ADDR 0x10490000
65 /* Combiner */
66 #define EXYNOS4210_EXT_COMBINER_BASE_ADDR 0x10440000
67 #define EXYNOS4210_INT_COMBINER_BASE_ADDR 0x10448000
69 /* PMU SFR base address */
70 #define EXYNOS4210_PMU_BASE_ADDR 0x10020000
72 /* Display controllers (FIMD) */
73 #define EXYNOS4210_FIMD0_BASE_ADDR 0x11C00000
75 static uint8_t chipid_and_omr[] = { 0x11, 0x02, 0x21, 0x43,
76 0x09, 0x00, 0x00, 0x00 };
78 void exynos4210_write_secondary(ARMCPU *cpu,
79 const struct arm_boot_info *info)
81 int n;
82 uint32_t smpboot[] = {
83 0xe59f3034, /* ldr r3, External gic_cpu_if */
84 0xe59f2034, /* ldr r2, Internal gic_cpu_if */
85 0xe59f0034, /* ldr r0, startaddr */
86 0xe3a01001, /* mov r1, #1 */
87 0xe5821000, /* str r1, [r2] */
88 0xe5831000, /* str r1, [r3] */
89 0xe3a010ff, /* mov r1, #0xff */
90 0xe5821004, /* str r1, [r2, #4] */
91 0xe5831004, /* str r1, [r3, #4] */
92 0xf57ff04f, /* dsb */
93 0xe320f003, /* wfi */
94 0xe5901000, /* ldr r1, [r0] */
95 0xe1110001, /* tst r1, r1 */
96 0x0afffffb, /* beq <wfi> */
97 0xe12fff11, /* bx r1 */
98 EXYNOS4210_EXT_GIC_CPU_BASE_ADDR,
99 0, /* gic_cpu_if: base address of Internal GIC CPU interface */
100 0 /* bootreg: Boot register address is held here */
102 smpboot[ARRAY_SIZE(smpboot) - 1] = info->smp_bootreg_addr;
103 smpboot[ARRAY_SIZE(smpboot) - 2] = info->gic_cpu_if_addr;
104 for (n = 0; n < ARRAY_SIZE(smpboot); n++) {
105 smpboot[n] = tswap32(smpboot[n]);
107 rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot),
108 info->smp_loader_start);
111 Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
112 unsigned long ram_size)
114 qemu_irq cpu_irq[EXYNOS4210_NCPUS];
115 int i, n;
116 Exynos4210State *s = g_new(Exynos4210State, 1);
117 qemu_irq *irqp;
118 qemu_irq gate_irq[EXYNOS4210_NCPUS][EXYNOS4210_IRQ_GATE_NINPUTS];
119 unsigned long mem_size;
120 DeviceState *dev;
121 SysBusDevice *busdev;
123 for (n = 0; n < EXYNOS4210_NCPUS; n++) {
124 s->cpu[n] = cpu_arm_init("cortex-a9");
125 if (!s->cpu[n]) {
126 fprintf(stderr, "Unable to find CPU %d definition\n", n);
127 exit(1);
130 /* Create PIC controller for each processor instance */
131 irqp = arm_pic_init_cpu(s->cpu[n]);
134 * Get GICs gpio_in cpu_irq to connect a combiner to them later.
135 * Use only IRQ for a while.
137 cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
140 /*** IRQs ***/
142 s->irq_table = exynos4210_init_irq(&s->irqs);
144 /* IRQ Gate */
145 for (i = 0; i < EXYNOS4210_NCPUS; i++) {
146 dev = qdev_create(NULL, "exynos4210.irq_gate");
147 qdev_prop_set_uint32(dev, "n_in", EXYNOS4210_IRQ_GATE_NINPUTS);
148 qdev_init_nofail(dev);
149 /* Get IRQ Gate input in gate_irq */
150 for (n = 0; n < EXYNOS4210_IRQ_GATE_NINPUTS; n++) {
151 gate_irq[i][n] = qdev_get_gpio_in(dev, n);
153 busdev = sysbus_from_qdev(dev);
155 /* Connect IRQ Gate output to cpu_irq */
156 sysbus_connect_irq(busdev, 0, cpu_irq[i]);
159 /* Private memory region and Internal GIC */
160 dev = qdev_create(NULL, "a9mpcore_priv");
161 qdev_prop_set_uint32(dev, "num-cpu", EXYNOS4210_NCPUS);
162 qdev_init_nofail(dev);
163 busdev = sysbus_from_qdev(dev);
164 sysbus_mmio_map(busdev, 0, EXYNOS4210_SMP_PRIVATE_BASE_ADDR);
165 for (n = 0; n < EXYNOS4210_NCPUS; n++) {
166 sysbus_connect_irq(busdev, n, gate_irq[n][0]);
168 for (n = 0; n < EXYNOS4210_INT_GIC_NIRQ; n++) {
169 s->irqs.int_gic_irq[n] = qdev_get_gpio_in(dev, n);
172 /* Cache controller */
173 sysbus_create_simple("l2x0", EXYNOS4210_L2X0_BASE_ADDR, NULL);
175 /* External GIC */
176 dev = qdev_create(NULL, "exynos4210.gic");
177 qdev_prop_set_uint32(dev, "num-cpu", EXYNOS4210_NCPUS);
178 qdev_init_nofail(dev);
179 busdev = sysbus_from_qdev(dev);
180 /* Map CPU interface */
181 sysbus_mmio_map(busdev, 0, EXYNOS4210_EXT_GIC_CPU_BASE_ADDR);
182 /* Map Distributer interface */
183 sysbus_mmio_map(busdev, 1, EXYNOS4210_EXT_GIC_DIST_BASE_ADDR);
184 for (n = 0; n < EXYNOS4210_NCPUS; n++) {
185 sysbus_connect_irq(busdev, n, gate_irq[n][1]);
187 for (n = 0; n < EXYNOS4210_EXT_GIC_NIRQ; n++) {
188 s->irqs.ext_gic_irq[n] = qdev_get_gpio_in(dev, n);
191 /* Internal Interrupt Combiner */
192 dev = qdev_create(NULL, "exynos4210.combiner");
193 qdev_init_nofail(dev);
194 busdev = sysbus_from_qdev(dev);
195 for (n = 0; n < EXYNOS4210_MAX_INT_COMBINER_OUT_IRQ; n++) {
196 sysbus_connect_irq(busdev, n, s->irqs.int_gic_irq[n]);
198 exynos4210_combiner_get_gpioin(&s->irqs, dev, 0);
199 sysbus_mmio_map(busdev, 0, EXYNOS4210_INT_COMBINER_BASE_ADDR);
201 /* External Interrupt Combiner */
202 dev = qdev_create(NULL, "exynos4210.combiner");
203 qdev_prop_set_uint32(dev, "external", 1);
204 qdev_init_nofail(dev);
205 busdev = sysbus_from_qdev(dev);
206 for (n = 0; n < EXYNOS4210_MAX_INT_COMBINER_OUT_IRQ; n++) {
207 sysbus_connect_irq(busdev, n, s->irqs.ext_gic_irq[n]);
209 exynos4210_combiner_get_gpioin(&s->irqs, dev, 1);
210 sysbus_mmio_map(busdev, 0, EXYNOS4210_EXT_COMBINER_BASE_ADDR);
212 /* Initialize board IRQs. */
213 exynos4210_init_board_irqs(&s->irqs);
215 /*** Memory ***/
217 /* Chip-ID and OMR */
218 memory_region_init_ram_ptr(&s->chipid_mem, "exynos4210.chipid",
219 sizeof(chipid_and_omr), chipid_and_omr);
220 memory_region_set_readonly(&s->chipid_mem, true);
221 memory_region_add_subregion(system_mem, EXYNOS4210_CHIPID_ADDR,
222 &s->chipid_mem);
224 /* Internal ROM */
225 memory_region_init_ram(&s->irom_mem, "exynos4210.irom",
226 EXYNOS4210_IROM_SIZE);
227 memory_region_set_readonly(&s->irom_mem, true);
228 memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR,
229 &s->irom_mem);
230 /* mirror of iROM */
231 memory_region_init_alias(&s->irom_alias_mem, "exynos4210.irom_alias",
232 &s->irom_mem,
234 EXYNOS4210_IROM_SIZE);
235 memory_region_set_readonly(&s->irom_alias_mem, true);
236 memory_region_add_subregion(system_mem, EXYNOS4210_IROM_MIRROR_BASE_ADDR,
237 &s->irom_alias_mem);
239 /* Internal RAM */
240 memory_region_init_ram(&s->iram_mem, "exynos4210.iram",
241 EXYNOS4210_IRAM_SIZE);
242 vmstate_register_ram_global(&s->iram_mem);
243 memory_region_add_subregion(system_mem, EXYNOS4210_IRAM_BASE_ADDR,
244 &s->iram_mem);
246 /* DRAM */
247 mem_size = ram_size;
248 if (mem_size > EXYNOS4210_DRAM_MAX_SIZE) {
249 memory_region_init_ram(&s->dram1_mem, "exynos4210.dram1",
250 mem_size - EXYNOS4210_DRAM_MAX_SIZE);
251 vmstate_register_ram_global(&s->dram1_mem);
252 memory_region_add_subregion(system_mem, EXYNOS4210_DRAM1_BASE_ADDR,
253 &s->dram1_mem);
254 mem_size = EXYNOS4210_DRAM_MAX_SIZE;
256 memory_region_init_ram(&s->dram0_mem, "exynos4210.dram0", mem_size);
257 vmstate_register_ram_global(&s->dram0_mem);
258 memory_region_add_subregion(system_mem, EXYNOS4210_DRAM0_BASE_ADDR,
259 &s->dram0_mem);
261 /* PMU.
262 * The only reason of existence at the moment is that secondary CPU boot
263 * loader uses PMU INFORM5 register as a holding pen.
265 sysbus_create_simple("exynos4210.pmu", EXYNOS4210_PMU_BASE_ADDR, NULL);
267 /* PWM */
268 sysbus_create_varargs("exynos4210.pwm", EXYNOS4210_PWM_BASE_ADDR,
269 s->irq_table[exynos4210_get_irq(22, 0)],
270 s->irq_table[exynos4210_get_irq(22, 1)],
271 s->irq_table[exynos4210_get_irq(22, 2)],
272 s->irq_table[exynos4210_get_irq(22, 3)],
273 s->irq_table[exynos4210_get_irq(22, 4)],
274 NULL);
275 /* RTC */
276 sysbus_create_varargs("exynos4210.rtc", EXYNOS4210_RTC_BASE_ADDR,
277 s->irq_table[exynos4210_get_irq(23, 0)],
278 s->irq_table[exynos4210_get_irq(23, 1)],
279 NULL);
281 /* Multi Core Timer */
282 dev = qdev_create(NULL, "exynos4210.mct");
283 qdev_init_nofail(dev);
284 busdev = sysbus_from_qdev(dev);
285 for (n = 0; n < 4; n++) {
286 /* Connect global timer interrupts to Combiner gpio_in */
287 sysbus_connect_irq(busdev, n,
288 s->irq_table[exynos4210_get_irq(1, 4 + n)]);
290 /* Connect local timer interrupts to Combiner gpio_in */
291 sysbus_connect_irq(busdev, 4,
292 s->irq_table[exynos4210_get_irq(51, 0)]);
293 sysbus_connect_irq(busdev, 5,
294 s->irq_table[exynos4210_get_irq(35, 3)]);
295 sysbus_mmio_map(busdev, 0, EXYNOS4210_MCT_BASE_ADDR);
297 /*** I2C ***/
298 for (n = 0; n < EXYNOS4210_I2C_NUMBER; n++) {
299 uint32_t addr = EXYNOS4210_I2C_BASE_ADDR + EXYNOS4210_I2C_SHIFT * n;
300 qemu_irq i2c_irq;
302 if (n < 8) {
303 i2c_irq = s->irq_table[exynos4210_get_irq(EXYNOS4210_I2C_INTG, n)];
304 } else {
305 i2c_irq = s->irq_table[exynos4210_get_irq(EXYNOS4210_HDMI_INTG, 1)];
308 dev = qdev_create(NULL, "exynos4210.i2c");
309 qdev_init_nofail(dev);
310 busdev = sysbus_from_qdev(dev);
311 sysbus_connect_irq(busdev, 0, i2c_irq);
312 sysbus_mmio_map(busdev, 0, addr);
313 s->i2c_if[n] = (i2c_bus *)qdev_get_child_bus(dev, "i2c");
317 /*** UARTs ***/
318 exynos4210_uart_create(EXYNOS4210_UART0_BASE_ADDR,
319 EXYNOS4210_UART0_FIFO_SIZE, 0, NULL,
320 s->irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 0)]);
322 exynos4210_uart_create(EXYNOS4210_UART1_BASE_ADDR,
323 EXYNOS4210_UART1_FIFO_SIZE, 1, NULL,
324 s->irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 1)]);
326 exynos4210_uart_create(EXYNOS4210_UART2_BASE_ADDR,
327 EXYNOS4210_UART2_FIFO_SIZE, 2, NULL,
328 s->irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 2)]);
330 exynos4210_uart_create(EXYNOS4210_UART3_BASE_ADDR,
331 EXYNOS4210_UART3_FIFO_SIZE, 3, NULL,
332 s->irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 3)]);
334 /*** Display controller (FIMD) ***/
335 sysbus_create_varargs("exynos4210.fimd", EXYNOS4210_FIMD0_BASE_ADDR,
336 s->irq_table[exynos4210_get_irq(11, 0)],
337 s->irq_table[exynos4210_get_irq(11, 1)],
338 s->irq_table[exynos4210_get_irq(11, 2)],
339 NULL);
341 return s;