2 * Samsung exynos4210 Interrupt Combiner
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/>.
24 * Exynos4210 Combiner represents an OR gate for SOC's IRQ lines. It combines
25 * IRQ sources into groups and provides signal output to GIC from each group. It
26 * is driven by common mask and enable/disable logic. Take a note that not all
27 * IRQs are passed to GIC through Combiner.
30 #include "qemu/osdep.h"
31 #include "hw/sysbus.h"
32 #include "migration/vmstate.h"
33 #include "qemu/module.h"
35 #include "hw/arm/exynos4210.h"
38 #include "hw/qdev-properties.h"
40 //#define DEBUG_COMBINER
43 #define DPRINTF(fmt, ...) \
44 do { fprintf(stdout, "COMBINER: [%s:%d] " fmt, __func__ , __LINE__, \
45 ## __VA_ARGS__); } while (0)
47 #define DPRINTF(fmt, ...) do {} while (0)
50 #define IIC_NGRP 64 /* Internal Interrupt Combiner
52 #define IIC_NIRQ (IIC_NGRP * 8)/* Internal Interrupt Combiner
54 #define IIC_REGION_SIZE 0x108 /* Size of memory mapped region */
55 #define IIC_REGSET_SIZE 0x41
58 * State for each output signal of internal combiner
60 typedef struct CombinerGroupState {
61 uint8_t src_mask; /* 1 - source enabled, 0 - disabled */
62 uint8_t src_pending; /* Pending source interrupts before masking */
65 #define TYPE_EXYNOS4210_COMBINER "exynos4210.combiner"
66 #define EXYNOS4210_COMBINER(obj) \
67 OBJECT_CHECK(Exynos4210CombinerState, (obj), TYPE_EXYNOS4210_COMBINER)
69 typedef struct Exynos4210CombinerState {
70 SysBusDevice parent_obj;
74 struct CombinerGroupState group[IIC_NGRP];
75 uint32_t reg_set[IIC_REGSET_SIZE];
77 uint32_t external; /* 1 means that this combiner is external */
79 qemu_irq output_irq[IIC_NGRP];
80 } Exynos4210CombinerState;
82 static const VMStateDescription vmstate_exynos4210_combiner_group_state = {
83 .name = "exynos4210.combiner.groupstate",
85 .minimum_version_id = 1,
86 .fields = (VMStateField[]) {
87 VMSTATE_UINT8(src_mask, CombinerGroupState),
88 VMSTATE_UINT8(src_pending, CombinerGroupState),
93 static const VMStateDescription vmstate_exynos4210_combiner = {
94 .name = "exynos4210.combiner",
96 .minimum_version_id = 1,
97 .fields = (VMStateField[]) {
98 VMSTATE_STRUCT_ARRAY(group, Exynos4210CombinerState, IIC_NGRP, 0,
99 vmstate_exynos4210_combiner_group_state, CombinerGroupState),
100 VMSTATE_UINT32_ARRAY(reg_set, Exynos4210CombinerState,
102 VMSTATE_UINT32_ARRAY(icipsr, Exynos4210CombinerState, 2),
103 VMSTATE_UINT32(external, Exynos4210CombinerState),
104 VMSTATE_END_OF_LIST()
109 * Get Combiner input GPIO into irqs structure
111 void exynos4210_combiner_get_gpioin(Exynos4210Irq *irqs, DeviceState *dev,
119 max = ext ? EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ :
120 EXYNOS4210_MAX_INT_COMBINER_IN_IRQ;
121 irq = ext ? irqs->ext_combiner_irq : irqs->int_combiner_irq;
124 * Some IRQs of Int/External Combiner are going to two Combiners groups,
127 for (n = 0; n < max; n++) {
129 bit = EXYNOS4210_COMBINER_GET_BIT_NUM(n);
132 /* MDNIE_LCD1 INTG1 */
133 case EXYNOS4210_COMBINER_GET_IRQ_NUM(1, 0) ...
134 EXYNOS4210_COMBINER_GET_IRQ_NUM(1, 3):
135 irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
136 irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(0, bit + 4)]);
140 case EXYNOS4210_COMBINER_GET_IRQ_NUM(3, 4):
141 irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
142 irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(2, bit)]);
146 case EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 0) ...
147 EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 3):
148 irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
149 irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(11, bit + 4)]);
152 /* Multi-Core Timer INTG12 */
153 case EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 4) ...
154 EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 8):
155 irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
156 irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit + 4)]);
159 /* Multi-Core Timer INTG35 */
160 case EXYNOS4210_COMBINER_GET_IRQ_NUM(35, 4) ...
161 EXYNOS4210_COMBINER_GET_IRQ_NUM(35, 8):
162 irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
163 irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit + 4)]);
166 /* Multi-Core Timer INTG51 */
167 case EXYNOS4210_COMBINER_GET_IRQ_NUM(51, 4) ...
168 EXYNOS4210_COMBINER_GET_IRQ_NUM(51, 8):
169 irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
170 irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit + 4)]);
173 /* Multi-Core Timer INTG53 */
174 case EXYNOS4210_COMBINER_GET_IRQ_NUM(53, 4) ...
175 EXYNOS4210_COMBINER_GET_IRQ_NUM(53, 8):
176 irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
177 irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit + 4)]);
181 irq[n] = qdev_get_gpio_in(dev, n);
186 exynos4210_combiner_read(void *opaque, hwaddr offset, unsigned size)
188 struct Exynos4210CombinerState *s =
189 (struct Exynos4210CombinerState *)opaque;
190 uint32_t req_quad_base_n; /* Base of registers quad. Multiply it by 4 and
191 get a start of corresponding group quad */
192 uint32_t grp_quad_base_n; /* Base of group quad */
193 uint32_t reg_n; /* Register number inside the quad */
196 req_quad_base_n = offset >> 4;
197 grp_quad_base_n = req_quad_base_n << 2;
198 reg_n = (offset - (req_quad_base_n << 4)) >> 2;
200 if (req_quad_base_n >= IIC_NGRP) {
201 /* Read of ICIPSR register */
202 return s->icipsr[reg_n];
210 val |= s->group[grp_quad_base_n].src_pending;
211 val |= s->group[grp_quad_base_n + 1].src_pending << 8;
212 val |= s->group[grp_quad_base_n + 2].src_pending << 16;
213 val |= s->group[grp_quad_base_n + 3].src_pending << 24;
217 val |= s->group[grp_quad_base_n].src_mask &
218 s->group[grp_quad_base_n].src_pending;
219 val |= (s->group[grp_quad_base_n + 1].src_mask &
220 s->group[grp_quad_base_n + 1].src_pending) << 8;
221 val |= (s->group[grp_quad_base_n + 2].src_mask &
222 s->group[grp_quad_base_n + 2].src_pending) << 16;
223 val |= (s->group[grp_quad_base_n + 3].src_mask &
224 s->group[grp_quad_base_n + 3].src_pending) << 24;
227 if (offset >> 2 >= IIC_REGSET_SIZE) {
228 hw_error("exynos4210.combiner: overflow of reg_set by 0x"
229 TARGET_FMT_plx "offset\n", offset);
231 val = s->reg_set[offset >> 2];
237 static void exynos4210_combiner_update(void *opaque, uint8_t group_n)
239 struct Exynos4210CombinerState *s =
240 (struct Exynos4210CombinerState *)opaque;
242 /* Send interrupt if needed */
243 if (s->group[group_n].src_mask & s->group[group_n].src_pending) {
244 #ifdef DEBUG_COMBINER
247 DPRINTF("%s raise IRQ[%d]\n", s->external ? "EXT" : "INT", group_n);
251 /* Set Combiner interrupt pending status after masking */
253 s->icipsr[1] |= 1 << (group_n - 32);
255 s->icipsr[0] |= 1 << group_n;
258 qemu_irq_raise(s->output_irq[group_n]);
260 #ifdef DEBUG_COMBINER
263 DPRINTF("%s lower IRQ[%d]\n", s->external ? "EXT" : "INT", group_n);
267 /* Set Combiner interrupt pending status after masking */
269 s->icipsr[1] &= ~(1 << (group_n - 32));
271 s->icipsr[0] &= ~(1 << group_n);
274 qemu_irq_lower(s->output_irq[group_n]);
278 static void exynos4210_combiner_write(void *opaque, hwaddr offset,
279 uint64_t val, unsigned size)
281 struct Exynos4210CombinerState *s =
282 (struct Exynos4210CombinerState *)opaque;
283 uint32_t req_quad_base_n; /* Base of registers quad. Multiply it by 4 and
284 get a start of corresponding group quad */
285 uint32_t grp_quad_base_n; /* Base of group quad */
286 uint32_t reg_n; /* Register number inside the quad */
288 req_quad_base_n = offset >> 4;
289 grp_quad_base_n = req_quad_base_n << 2;
290 reg_n = (offset - (req_quad_base_n << 4)) >> 2;
292 if (req_quad_base_n >= IIC_NGRP) {
293 hw_error("exynos4210.combiner: unallowed write access at offset 0x"
294 TARGET_FMT_plx "\n", offset);
299 hw_error("exynos4210.combiner: unallowed write access at offset 0x"
300 TARGET_FMT_plx "\n", offset);
304 if (offset >> 2 >= IIC_REGSET_SIZE) {
305 hw_error("exynos4210.combiner: overflow of reg_set by 0x"
306 TARGET_FMT_plx "offset\n", offset);
308 s->reg_set[offset >> 2] = val;
313 /* FIXME: what if irq is pending, allowed by mask, and we allow it
314 * again. Interrupt will rise again! */
316 DPRINTF("%s enable IRQ for groups %d, %d, %d, %d\n",
317 s->external ? "EXT" : "INT",
321 grp_quad_base_n + 3);
323 /* Enable interrupt sources */
324 s->group[grp_quad_base_n].src_mask |= val & 0xFF;
325 s->group[grp_quad_base_n + 1].src_mask |= (val & 0xFF00) >> 8;
326 s->group[grp_quad_base_n + 2].src_mask |= (val & 0xFF0000) >> 16;
327 s->group[grp_quad_base_n + 3].src_mask |= (val & 0xFF000000) >> 24;
329 exynos4210_combiner_update(s, grp_quad_base_n);
330 exynos4210_combiner_update(s, grp_quad_base_n + 1);
331 exynos4210_combiner_update(s, grp_quad_base_n + 2);
332 exynos4210_combiner_update(s, grp_quad_base_n + 3);
336 DPRINTF("%s disable IRQ for groups %d, %d, %d, %d\n",
337 s->external ? "EXT" : "INT",
341 grp_quad_base_n + 3);
343 /* Disable interrupt sources */
344 s->group[grp_quad_base_n].src_mask &= ~(val & 0xFF);
345 s->group[grp_quad_base_n + 1].src_mask &= ~((val & 0xFF00) >> 8);
346 s->group[grp_quad_base_n + 2].src_mask &= ~((val & 0xFF0000) >> 16);
347 s->group[grp_quad_base_n + 3].src_mask &= ~((val & 0xFF000000) >> 24);
349 exynos4210_combiner_update(s, grp_quad_base_n);
350 exynos4210_combiner_update(s, grp_quad_base_n + 1);
351 exynos4210_combiner_update(s, grp_quad_base_n + 2);
352 exynos4210_combiner_update(s, grp_quad_base_n + 3);
355 hw_error("exynos4210.combiner: unallowed write access at offset 0x"
356 TARGET_FMT_plx "\n", offset);
361 /* Get combiner group and bit from irq number */
362 static uint8_t get_combiner_group_and_bit(int irq, uint8_t *bit)
364 *bit = irq - ((irq >> 3) << 3);
368 /* Process a change in an external IRQ input. */
369 static void exynos4210_combiner_handler(void *opaque, int irq, int level)
371 struct Exynos4210CombinerState *s =
372 (struct Exynos4210CombinerState *)opaque;
373 uint8_t bit_n, group_n;
375 group_n = get_combiner_group_and_bit(irq, &bit_n);
377 if (s->external && group_n >= EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ) {
378 DPRINTF("%s unallowed IRQ group 0x%x\n", s->external ? "EXT" : "INT"
384 s->group[group_n].src_pending |= 1 << bit_n;
386 s->group[group_n].src_pending &= ~(1 << bit_n);
389 exynos4210_combiner_update(s, group_n);
392 static void exynos4210_combiner_reset(DeviceState *d)
394 struct Exynos4210CombinerState *s = (struct Exynos4210CombinerState *)d;
396 memset(&s->group, 0, sizeof(s->group));
397 memset(&s->reg_set, 0, sizeof(s->reg_set));
399 s->reg_set[0xC0 >> 2] = 0x01010101;
400 s->reg_set[0xC4 >> 2] = 0x01010101;
401 s->reg_set[0xD0 >> 2] = 0x01010101;
402 s->reg_set[0xD4 >> 2] = 0x01010101;
405 static const MemoryRegionOps exynos4210_combiner_ops = {
406 .read = exynos4210_combiner_read,
407 .write = exynos4210_combiner_write,
408 .endianness = DEVICE_NATIVE_ENDIAN,
412 * Internal Combiner initialization.
414 static void exynos4210_combiner_init(Object *obj)
416 DeviceState *dev = DEVICE(obj);
417 Exynos4210CombinerState *s = EXYNOS4210_COMBINER(obj);
418 SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
421 /* Allocate general purpose input signals and connect a handler to each of
423 qdev_init_gpio_in(dev, exynos4210_combiner_handler, IIC_NIRQ);
425 /* Connect SysBusDev irqs to device specific irqs */
426 for (i = 0; i < IIC_NGRP; i++) {
427 sysbus_init_irq(sbd, &s->output_irq[i]);
430 memory_region_init_io(&s->iomem, obj, &exynos4210_combiner_ops, s,
431 "exynos4210-combiner", IIC_REGION_SIZE);
432 sysbus_init_mmio(sbd, &s->iomem);
435 static Property exynos4210_combiner_properties[] = {
436 DEFINE_PROP_UINT32("external", Exynos4210CombinerState, external, 0),
437 DEFINE_PROP_END_OF_LIST(),
440 static void exynos4210_combiner_class_init(ObjectClass *klass, void *data)
442 DeviceClass *dc = DEVICE_CLASS(klass);
444 dc->reset = exynos4210_combiner_reset;
445 device_class_set_props(dc, exynos4210_combiner_properties);
446 dc->vmsd = &vmstate_exynos4210_combiner;
449 static const TypeInfo exynos4210_combiner_info = {
450 .name = TYPE_EXYNOS4210_COMBINER,
451 .parent = TYPE_SYS_BUS_DEVICE,
452 .instance_size = sizeof(Exynos4210CombinerState),
453 .instance_init = exynos4210_combiner_init,
454 .class_init = exynos4210_combiner_class_init,
457 static void exynos4210_combiner_register_types(void)
459 type_register_static(&exynos4210_combiner_info);
462 type_init(exynos4210_combiner_register_types)