2 * Samsung exynos4210 Interrupt Combiner
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
7 * Evgeny Voevodin <e.voevodin@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 (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"
39 #include "qom/object.h"
41 //#define DEBUG_COMBINER
44 #define DPRINTF(fmt, ...) \
45 do { fprintf(stdout, "COMBINER: [%s:%d] " fmt, __func__ , __LINE__, \
46 ## __VA_ARGS__); } while (0)
48 #define DPRINTF(fmt, ...) do {} while (0)
51 #define IIC_NGRP 64 /* Internal Interrupt Combiner
53 #define IIC_NIRQ (IIC_NGRP * 8)/* Internal Interrupt Combiner
55 #define IIC_REGION_SIZE 0x108 /* Size of memory mapped region */
56 #define IIC_REGSET_SIZE 0x41
59 * State for each output signal of internal combiner
61 typedef struct CombinerGroupState
{
62 uint8_t src_mask
; /* 1 - source enabled, 0 - disabled */
63 uint8_t src_pending
; /* Pending source interrupts before masking */
66 #define TYPE_EXYNOS4210_COMBINER "exynos4210.combiner"
67 OBJECT_DECLARE_SIMPLE_TYPE(Exynos4210CombinerState
, EXYNOS4210_COMBINER
)
69 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
];
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 exynos4210_combiner_read(void *opaque
, hwaddr offset
, unsigned size
)
111 struct Exynos4210CombinerState
*s
=
112 (struct Exynos4210CombinerState
*)opaque
;
113 uint32_t req_quad_base_n
; /* Base of registers quad. Multiply it by 4 and
114 get a start of corresponding group quad */
115 uint32_t grp_quad_base_n
; /* Base of group quad */
116 uint32_t reg_n
; /* Register number inside the quad */
119 req_quad_base_n
= offset
>> 4;
120 grp_quad_base_n
= req_quad_base_n
<< 2;
121 reg_n
= (offset
- (req_quad_base_n
<< 4)) >> 2;
123 if (req_quad_base_n
>= IIC_NGRP
) {
124 /* Read of ICIPSR register */
125 return s
->icipsr
[reg_n
];
133 val
|= s
->group
[grp_quad_base_n
].src_pending
;
134 val
|= s
->group
[grp_quad_base_n
+ 1].src_pending
<< 8;
135 val
|= s
->group
[grp_quad_base_n
+ 2].src_pending
<< 16;
136 val
|= s
->group
[grp_quad_base_n
+ 3].src_pending
<< 24;
140 val
|= s
->group
[grp_quad_base_n
].src_mask
&
141 s
->group
[grp_quad_base_n
].src_pending
;
142 val
|= (s
->group
[grp_quad_base_n
+ 1].src_mask
&
143 s
->group
[grp_quad_base_n
+ 1].src_pending
) << 8;
144 val
|= (s
->group
[grp_quad_base_n
+ 2].src_mask
&
145 s
->group
[grp_quad_base_n
+ 2].src_pending
) << 16;
146 val
|= (s
->group
[grp_quad_base_n
+ 3].src_mask
&
147 s
->group
[grp_quad_base_n
+ 3].src_pending
) << 24;
150 if (offset
>> 2 >= IIC_REGSET_SIZE
) {
151 hw_error("exynos4210.combiner: overflow of reg_set by 0x"
152 TARGET_FMT_plx
"offset\n", offset
);
154 val
= s
->reg_set
[offset
>> 2];
159 static void exynos4210_combiner_update(void *opaque
, uint8_t group_n
)
161 struct Exynos4210CombinerState
*s
=
162 (struct Exynos4210CombinerState
*)opaque
;
164 /* Send interrupt if needed */
165 if (s
->group
[group_n
].src_mask
& s
->group
[group_n
].src_pending
) {
166 #ifdef DEBUG_COMBINER
169 DPRINTF("%s raise IRQ[%d]\n", s
->external
? "EXT" : "INT", group_n
);
173 /* Set Combiner interrupt pending status after masking */
175 s
->icipsr
[1] |= 1 << (group_n
- 32);
177 s
->icipsr
[0] |= 1 << group_n
;
180 qemu_irq_raise(s
->output_irq
[group_n
]);
182 #ifdef DEBUG_COMBINER
185 DPRINTF("%s lower IRQ[%d]\n", s
->external
? "EXT" : "INT", group_n
);
189 /* Set Combiner interrupt pending status after masking */
191 s
->icipsr
[1] &= ~(1 << (group_n
- 32));
193 s
->icipsr
[0] &= ~(1 << group_n
);
196 qemu_irq_lower(s
->output_irq
[group_n
]);
200 static void exynos4210_combiner_write(void *opaque
, hwaddr offset
,
201 uint64_t val
, unsigned size
)
203 struct Exynos4210CombinerState
*s
=
204 (struct Exynos4210CombinerState
*)opaque
;
205 uint32_t req_quad_base_n
; /* Base of registers quad. Multiply it by 4 and
206 get a start of corresponding group quad */
207 uint32_t grp_quad_base_n
; /* Base of group quad */
208 uint32_t reg_n
; /* Register number inside the quad */
210 req_quad_base_n
= offset
>> 4;
211 grp_quad_base_n
= req_quad_base_n
<< 2;
212 reg_n
= (offset
- (req_quad_base_n
<< 4)) >> 2;
214 if (req_quad_base_n
>= IIC_NGRP
) {
215 hw_error("exynos4210.combiner: unallowed write access at offset 0x"
216 TARGET_FMT_plx
"\n", offset
);
221 hw_error("exynos4210.combiner: unallowed write access at offset 0x"
222 TARGET_FMT_plx
"\n", offset
);
226 if (offset
>> 2 >= IIC_REGSET_SIZE
) {
227 hw_error("exynos4210.combiner: overflow of reg_set by 0x"
228 TARGET_FMT_plx
"offset\n", offset
);
230 s
->reg_set
[offset
>> 2] = val
;
235 /* FIXME: what if irq is pending, allowed by mask, and we allow it
236 * again. Interrupt will rise again! */
238 DPRINTF("%s enable IRQ for groups %d, %d, %d, %d\n",
239 s
->external
? "EXT" : "INT",
243 grp_quad_base_n
+ 3);
245 /* Enable interrupt sources */
246 s
->group
[grp_quad_base_n
].src_mask
|= val
& 0xFF;
247 s
->group
[grp_quad_base_n
+ 1].src_mask
|= (val
& 0xFF00) >> 8;
248 s
->group
[grp_quad_base_n
+ 2].src_mask
|= (val
& 0xFF0000) >> 16;
249 s
->group
[grp_quad_base_n
+ 3].src_mask
|= (val
& 0xFF000000) >> 24;
251 exynos4210_combiner_update(s
, grp_quad_base_n
);
252 exynos4210_combiner_update(s
, grp_quad_base_n
+ 1);
253 exynos4210_combiner_update(s
, grp_quad_base_n
+ 2);
254 exynos4210_combiner_update(s
, grp_quad_base_n
+ 3);
258 DPRINTF("%s disable IRQ for groups %d, %d, %d, %d\n",
259 s
->external
? "EXT" : "INT",
263 grp_quad_base_n
+ 3);
265 /* Disable interrupt sources */
266 s
->group
[grp_quad_base_n
].src_mask
&= ~(val
& 0xFF);
267 s
->group
[grp_quad_base_n
+ 1].src_mask
&= ~((val
& 0xFF00) >> 8);
268 s
->group
[grp_quad_base_n
+ 2].src_mask
&= ~((val
& 0xFF0000) >> 16);
269 s
->group
[grp_quad_base_n
+ 3].src_mask
&= ~((val
& 0xFF000000) >> 24);
271 exynos4210_combiner_update(s
, grp_quad_base_n
);
272 exynos4210_combiner_update(s
, grp_quad_base_n
+ 1);
273 exynos4210_combiner_update(s
, grp_quad_base_n
+ 2);
274 exynos4210_combiner_update(s
, grp_quad_base_n
+ 3);
277 hw_error("exynos4210.combiner: unallowed write access at offset 0x"
278 TARGET_FMT_plx
"\n", offset
);
283 /* Get combiner group and bit from irq number */
284 static uint8_t get_combiner_group_and_bit(int irq
, uint8_t *bit
)
286 *bit
= irq
- ((irq
>> 3) << 3);
290 /* Process a change in an external IRQ input. */
291 static void exynos4210_combiner_handler(void *opaque
, int irq
, int level
)
293 struct Exynos4210CombinerState
*s
=
294 (struct Exynos4210CombinerState
*)opaque
;
295 uint8_t bit_n
, group_n
;
297 group_n
= get_combiner_group_and_bit(irq
, &bit_n
);
299 if (s
->external
&& group_n
>= EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ
) {
300 DPRINTF("%s unallowed IRQ group 0x%x\n", s
->external
? "EXT" : "INT"
306 s
->group
[group_n
].src_pending
|= 1 << bit_n
;
308 s
->group
[group_n
].src_pending
&= ~(1 << bit_n
);
311 exynos4210_combiner_update(s
, group_n
);
314 static void exynos4210_combiner_reset(DeviceState
*d
)
316 struct Exynos4210CombinerState
*s
= (struct Exynos4210CombinerState
*)d
;
318 memset(&s
->group
, 0, sizeof(s
->group
));
319 memset(&s
->reg_set
, 0, sizeof(s
->reg_set
));
321 s
->reg_set
[0xC0 >> 2] = 0x01010101;
322 s
->reg_set
[0xC4 >> 2] = 0x01010101;
323 s
->reg_set
[0xD0 >> 2] = 0x01010101;
324 s
->reg_set
[0xD4 >> 2] = 0x01010101;
327 static const MemoryRegionOps exynos4210_combiner_ops
= {
328 .read
= exynos4210_combiner_read
,
329 .write
= exynos4210_combiner_write
,
330 .endianness
= DEVICE_NATIVE_ENDIAN
,
334 * Internal Combiner initialization.
336 static void exynos4210_combiner_init(Object
*obj
)
338 DeviceState
*dev
= DEVICE(obj
);
339 Exynos4210CombinerState
*s
= EXYNOS4210_COMBINER(obj
);
340 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
343 /* Allocate general purpose input signals and connect a handler to each of
345 qdev_init_gpio_in(dev
, exynos4210_combiner_handler
, IIC_NIRQ
);
347 /* Connect SysBusDev irqs to device specific irqs */
348 for (i
= 0; i
< IIC_NGRP
; i
++) {
349 sysbus_init_irq(sbd
, &s
->output_irq
[i
]);
352 memory_region_init_io(&s
->iomem
, obj
, &exynos4210_combiner_ops
, s
,
353 "exynos4210-combiner", IIC_REGION_SIZE
);
354 sysbus_init_mmio(sbd
, &s
->iomem
);
357 static Property exynos4210_combiner_properties
[] = {
358 DEFINE_PROP_UINT32("external", Exynos4210CombinerState
, external
, 0),
359 DEFINE_PROP_END_OF_LIST(),
362 static void exynos4210_combiner_class_init(ObjectClass
*klass
, void *data
)
364 DeviceClass
*dc
= DEVICE_CLASS(klass
);
366 dc
->reset
= exynos4210_combiner_reset
;
367 device_class_set_props(dc
, exynos4210_combiner_properties
);
368 dc
->vmsd
= &vmstate_exynos4210_combiner
;
371 static const TypeInfo exynos4210_combiner_info
= {
372 .name
= TYPE_EXYNOS4210_COMBINER
,
373 .parent
= TYPE_SYS_BUS_DEVICE
,
374 .instance_size
= sizeof(Exynos4210CombinerState
),
375 .instance_init
= exynos4210_combiner_init
,
376 .class_init
= exynos4210_combiner_class_init
,
379 static void exynos4210_combiner_register_types(void)
381 type_register_static(&exynos4210_combiner_info
);
384 type_init(exynos4210_combiner_register_types
)