2 * Samsung exynos4210 GIC implementation. Based on hw/arm_gic.c
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
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 (at your
12 * option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License 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/>.
23 #include "hw/sysbus.h"
24 #include "qemu-common.h"
26 #include "hw/arm/exynos4210.h"
29 EXT_GIC_ID_MDMA_LCD0 = 66,
66 EXT_GIC_ID_USB_DEVICE,
73 EXT_GIC_ID_MIPI_CSI_4LANE,
74 EXT_GIC_ID_MIPI_DSI_4LANE,
75 EXT_GIC_ID_MIPI_CSI_2LANE,
76 EXT_GIC_ID_MIPI_DSI_2LANE,
77 EXT_GIC_ID_ONENAND_AUDI,
94 EXT_GIC_ID_EXTINT0 = 48,
113 * External GIC sources which are not from External Interrupt Combiner or
114 * External Interrupts are starting from EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ,
115 * which is INTG16 in Internal Interrupt Combiner.
119 combiner_grp_to_gic_id[64-EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ][8] = {
120 /* int combiner groups 16-19 */
122 /* int combiner group 20 */
123 { 0, EXT_GIC_ID_MDMA_LCD0 },
124 /* int combiner group 21 */
125 { EXT_GIC_ID_PDMA0, EXT_GIC_ID_PDMA1 },
126 /* int combiner group 22 */
127 { EXT_GIC_ID_TIMER0, EXT_GIC_ID_TIMER1, EXT_GIC_ID_TIMER2,
128 EXT_GIC_ID_TIMER3, EXT_GIC_ID_TIMER4 },
129 /* int combiner group 23 */
130 { EXT_GIC_ID_RTC_ALARM, EXT_GIC_ID_RTC_TIC },
131 /* int combiner group 24 */
132 { EXT_GIC_ID_GPIO_XB, EXT_GIC_ID_GPIO_XA },
133 /* int combiner group 25 */
134 { EXT_GIC_ID_IEM_APC, EXT_GIC_ID_IEM_IEC },
135 /* int combiner group 26 */
136 { EXT_GIC_ID_UART0, EXT_GIC_ID_UART1, EXT_GIC_ID_UART2, EXT_GIC_ID_UART3,
138 /* int combiner group 27 */
139 { EXT_GIC_ID_I2C0, EXT_GIC_ID_I2C1, EXT_GIC_ID_I2C2, EXT_GIC_ID_I2C3,
140 EXT_GIC_ID_I2C4, EXT_GIC_ID_I2C5, EXT_GIC_ID_I2C6,
142 /* int combiner group 28 */
143 { EXT_GIC_ID_SPI0, EXT_GIC_ID_SPI1, EXT_GIC_ID_SPI2 , EXT_GIC_ID_USB_HOST},
144 /* int combiner group 29 */
145 { EXT_GIC_ID_HSMMC0, EXT_GIC_ID_HSMMC1, EXT_GIC_ID_HSMMC2,
146 EXT_GIC_ID_HSMMC3, EXT_GIC_ID_SDMMC },
147 /* int combiner group 30 */
148 { EXT_GIC_ID_MIPI_CSI_4LANE, EXT_GIC_ID_MIPI_CSI_2LANE },
149 /* int combiner group 31 */
150 { EXT_GIC_ID_MIPI_DSI_4LANE, EXT_GIC_ID_MIPI_DSI_2LANE },
151 /* int combiner group 32 */
152 { EXT_GIC_ID_FIMC0, EXT_GIC_ID_FIMC1 },
153 /* int combiner group 33 */
154 { EXT_GIC_ID_FIMC2, EXT_GIC_ID_FIMC3 },
155 /* int combiner group 34 */
156 { EXT_GIC_ID_ONENAND_AUDI, EXT_GIC_ID_NFC },
157 /* int combiner group 35 */
158 { 0, 0, 0, EXT_GIC_ID_MCT_L1, EXT_GIC_ID_MCT_G0, EXT_GIC_ID_MCT_G1 },
159 /* int combiner group 36 */
160 { EXT_GIC_ID_MIXER },
161 /* int combiner group 37 */
162 { EXT_GIC_ID_EXTINT4, EXT_GIC_ID_EXTINT5, EXT_GIC_ID_EXTINT6,
163 EXT_GIC_ID_EXTINT7 },
165 { }, { }, { }, { }, { }, { }, { }, { }, { }, { }, { }, { }, { },
166 /* int combiner group 51 */
167 { EXT_GIC_ID_MCT_L0, 0, 0, 0, EXT_GIC_ID_MCT_G0, EXT_GIC_ID_MCT_G1 },
170 /* int combiner group 53 */
171 { EXT_GIC_ID_WDT, 0, 0, 0, EXT_GIC_ID_MCT_G0, EXT_GIC_ID_MCT_G1 },
173 { }, { }, { }, { }, { }, { }, { }, { }, { }, { }
176 #define EXYNOS4210_GIC_NIRQ 160
178 #define EXYNOS4210_EXT_GIC_CPU_REGION_SIZE 0x10000
179 #define EXYNOS4210_EXT_GIC_DIST_REGION_SIZE 0x10000
181 #define EXYNOS4210_EXT_GIC_PER_CPU_OFFSET 0x8000
182 #define EXYNOS4210_EXT_GIC_CPU_GET_OFFSET(n) \
183 ((n) * EXYNOS4210_EXT_GIC_PER_CPU_OFFSET)
184 #define EXYNOS4210_EXT_GIC_DIST_GET_OFFSET(n) \
185 ((n) * EXYNOS4210_EXT_GIC_PER_CPU_OFFSET)
187 #define EXYNOS4210_GIC_CPU_REGION_SIZE 0x100
188 #define EXYNOS4210_GIC_DIST_REGION_SIZE 0x1000
190 static void exynos4210_irq_handler(void *opaque, int irq, int level)
192 Exynos4210Irq *s = (Exynos4210Irq *)opaque;
195 qemu_set_irq(s->board_irqs[irq], level);
199 * Initialize exynos4210 IRQ subsystem stub.
201 qemu_irq *exynos4210_init_irq(Exynos4210Irq *s)
203 return qemu_allocate_irqs(exynos4210_irq_handler, s,
204 EXYNOS4210_MAX_INT_COMBINER_IN_IRQ);
208 * Initialize board IRQs.
209 * These IRQs contain splitted Int/External Combiner and External Gic IRQs.
211 void exynos4210_init_board_irqs(Exynos4210Irq *s)
213 uint32_t grp, bit, irq_id, n;
215 for (n = 0; n < EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ; n++) {
216 s->board_irqs[n] = qemu_irq_split(s->int_combiner_irq[n],
217 s->ext_combiner_irq[n]);
220 if (n == EXYNOS4210_COMBINER_GET_IRQ_NUM(1, 4) ||
221 n == EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 4)) {
222 /* MCT_G0 is passed to External GIC */
223 irq_id = EXT_GIC_ID_MCT_G0;
225 if (n == EXYNOS4210_COMBINER_GET_IRQ_NUM(1, 5) ||
226 n == EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 5)) {
227 /* MCT_G1 is passed to External and GIC */
228 irq_id = EXT_GIC_ID_MCT_G1;
231 s->board_irqs[n] = qemu_irq_split(s->int_combiner_irq[n],
232 s->ext_gic_irq[irq_id-32]);
236 for (; n < EXYNOS4210_MAX_INT_COMBINER_IN_IRQ; n++) {
237 /* these IDs are passed to Internal Combiner and External GIC */
238 grp = EXYNOS4210_COMBINER_GET_GRP_NUM(n);
239 bit = EXYNOS4210_COMBINER_GET_BIT_NUM(n);
240 irq_id = combiner_grp_to_gic_id[grp -
241 EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ][bit];
244 s->board_irqs[n] = qemu_irq_split(s->int_combiner_irq[n],
245 s->ext_gic_irq[irq_id-32]);
251 * Get IRQ number from exynos4210 IRQ subsystem stub.
252 * To identify IRQ source use internal combiner group and bit number
254 * bit - bit number inside group
256 uint32_t exynos4210_get_irq(uint32_t grp, uint32_t bit)
258 return EXYNOS4210_COMBINER_GET_IRQ_NUM(grp, bit);
261 /********* GIC part *********/
263 #define TYPE_EXYNOS4210_GIC "exynos4210.gic"
264 #define EXYNOS4210_GIC(obj) \
265 OBJECT_CHECK(Exynos4210GicState, (obj), TYPE_EXYNOS4210_GIC)
268 SysBusDevice parent_obj;
270 MemoryRegion cpu_container;
271 MemoryRegion dist_container;
272 MemoryRegion cpu_alias[EXYNOS4210_NCPUS];
273 MemoryRegion dist_alias[EXYNOS4210_NCPUS];
276 } Exynos4210GicState;
278 static void exynos4210_gic_set_irq(void *opaque, int irq, int level)
280 Exynos4210GicState *s = (Exynos4210GicState *)opaque;
281 qemu_set_irq(qdev_get_gpio_in(s->gic, irq), level);
284 static int exynos4210_gic_init(SysBusDevice *sbd)
286 DeviceState *dev = DEVICE(sbd);
287 Exynos4210GicState *s = EXYNOS4210_GIC(dev);
289 const char cpu_prefix[] = "exynos4210-gic-alias_cpu";
290 const char dist_prefix[] = "exynos4210-gic-alias_dist";
291 char cpu_alias_name[sizeof(cpu_prefix) + 3];
292 char dist_alias_name[sizeof(cpu_prefix) + 3];
293 SysBusDevice *busdev;
295 s->gic = qdev_create(NULL, "arm_gic");
296 qdev_prop_set_uint32(s->gic, "num-cpu", s->num_cpu);
297 qdev_prop_set_uint32(s->gic, "num-irq", EXYNOS4210_GIC_NIRQ);
298 qdev_init_nofail(s->gic);
299 busdev = SYS_BUS_DEVICE(s->gic);
301 /* Pass through outbound IRQ lines from the GIC */
302 sysbus_pass_irq(sbd, busdev);
304 /* Pass through inbound GPIO lines to the GIC */
305 qdev_init_gpio_in(dev, exynos4210_gic_set_irq,
306 EXYNOS4210_GIC_NIRQ - 32);
308 memory_region_init(&s->cpu_container, OBJECT(s), "exynos4210-cpu-container",
309 EXYNOS4210_EXT_GIC_CPU_REGION_SIZE);
310 memory_region_init(&s->dist_container, OBJECT(s), "exynos4210-dist-container",
311 EXYNOS4210_EXT_GIC_DIST_REGION_SIZE);
313 for (i = 0; i < s->num_cpu; i++) {
314 /* Map CPU interface per SMP Core */
315 sprintf(cpu_alias_name, "%s%x", cpu_prefix, i);
316 memory_region_init_alias(&s->cpu_alias[i], OBJECT(s),
318 sysbus_mmio_get_region(busdev, 1),
320 EXYNOS4210_GIC_CPU_REGION_SIZE);
321 memory_region_add_subregion(&s->cpu_container,
322 EXYNOS4210_EXT_GIC_CPU_GET_OFFSET(i), &s->cpu_alias[i]);
324 /* Map Distributor per SMP Core */
325 sprintf(dist_alias_name, "%s%x", dist_prefix, i);
326 memory_region_init_alias(&s->dist_alias[i], OBJECT(s),
328 sysbus_mmio_get_region(busdev, 0),
330 EXYNOS4210_GIC_DIST_REGION_SIZE);
331 memory_region_add_subregion(&s->dist_container,
332 EXYNOS4210_EXT_GIC_DIST_GET_OFFSET(i), &s->dist_alias[i]);
335 sysbus_init_mmio(sbd, &s->cpu_container);
336 sysbus_init_mmio(sbd, &s->dist_container);
341 static Property exynos4210_gic_properties[] = {
342 DEFINE_PROP_UINT32("num-cpu", Exynos4210GicState, num_cpu, 1),
343 DEFINE_PROP_END_OF_LIST(),
346 static void exynos4210_gic_class_init(ObjectClass *klass, void *data)
348 DeviceClass *dc = DEVICE_CLASS(klass);
349 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
351 k->init = exynos4210_gic_init;
352 dc->props = exynos4210_gic_properties;
355 static const TypeInfo exynos4210_gic_info = {
356 .name = TYPE_EXYNOS4210_GIC,
357 .parent = TYPE_SYS_BUS_DEVICE,
358 .instance_size = sizeof(Exynos4210GicState),
359 .class_init = exynos4210_gic_class_init,
362 static void exynos4210_gic_register_types(void)
364 type_register_static(&exynos4210_gic_info);
367 type_init(exynos4210_gic_register_types)
369 /* IRQ OR Gate struct.
371 * This device models an OR gate. There are n_in input qdev gpio lines and one
372 * output sysbus IRQ line. The output IRQ level is formed as OR between all
376 #define TYPE_EXYNOS4210_IRQ_GATE "exynos4210.irq_gate"
377 #define EXYNOS4210_IRQ_GATE(obj) \
378 OBJECT_CHECK(Exynos4210IRQGateState, (obj), TYPE_EXYNOS4210_IRQ_GATE)
380 typedef struct Exynos4210IRQGateState {
381 SysBusDevice parent_obj;
383 uint32_t n_in; /* inputs amount */
384 uint32_t *level; /* input levels */
385 qemu_irq out; /* output IRQ */
386 } Exynos4210IRQGateState;
388 static Property exynos4210_irq_gate_properties[] = {
389 DEFINE_PROP_UINT32("n_in", Exynos4210IRQGateState, n_in, 1),
390 DEFINE_PROP_END_OF_LIST(),
393 static const VMStateDescription vmstate_exynos4210_irq_gate = {
394 .name = "exynos4210.irq_gate",
396 .minimum_version_id = 2,
397 .fields = (VMStateField[]) {
398 VMSTATE_VBUFFER_UINT32(level, Exynos4210IRQGateState, 1, NULL, 0, n_in),
399 VMSTATE_END_OF_LIST()
403 /* Process a change in IRQ input. */
404 static void exynos4210_irq_gate_handler(void *opaque, int irq, int level)
406 Exynos4210IRQGateState *s = (Exynos4210IRQGateState *)opaque;
409 assert(irq < s->n_in);
411 s->level[irq] = level;
413 for (i = 0; i < s->n_in; i++) {
414 if (s->level[i] >= 1) {
415 qemu_irq_raise(s->out);
420 qemu_irq_lower(s->out);
423 static void exynos4210_irq_gate_reset(DeviceState *d)
425 Exynos4210IRQGateState *s = EXYNOS4210_IRQ_GATE(d);
427 memset(s->level, 0, s->n_in * sizeof(*s->level));
431 * IRQ Gate initialization.
433 static int exynos4210_irq_gate_init(SysBusDevice *sbd)
435 DeviceState *dev = DEVICE(sbd);
436 Exynos4210IRQGateState *s = EXYNOS4210_IRQ_GATE(dev);
438 /* Allocate general purpose input signals and connect a handler to each of
440 qdev_init_gpio_in(dev, exynos4210_irq_gate_handler, s->n_in);
442 s->level = g_malloc0(s->n_in * sizeof(*s->level));
444 sysbus_init_irq(sbd, &s->out);
449 static void exynos4210_irq_gate_class_init(ObjectClass *klass, void *data)
451 DeviceClass *dc = DEVICE_CLASS(klass);
452 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
454 k->init = exynos4210_irq_gate_init;
455 dc->reset = exynos4210_irq_gate_reset;
456 dc->vmsd = &vmstate_exynos4210_irq_gate;
457 dc->props = exynos4210_irq_gate_properties;
460 static const TypeInfo exynos4210_irq_gate_info = {
461 .name = TYPE_EXYNOS4210_IRQ_GATE,
462 .parent = TYPE_SYS_BUS_DEVICE,
463 .instance_size = sizeof(Exynos4210IRQGateState),
464 .class_init = exynos4210_irq_gate_class_init,
467 static void exynos4210_irq_gate_register_types(void)
469 type_register_static(&exynos4210_irq_gate_info);
472 type_init(exynos4210_irq_gate_register_types)