2 * Samsung exynos4210 Multi Core timer
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/>.
26 * Consists of two timers. First represents Free Running Counter and second
27 * is used to measure interval from FRC to nearest comparator.
31 * | <-------------------------------------------------------------- |
32 * | --------------------------------------------frc---------------> |
33 * |______________________________________________|__________________|
34 * CMP0 CMP1 CMP2 | CMP3
40 * Problem: when implementing global timer as is, overflow arises.
41 * next_time = cur_time + period * count;
42 * period and count are 64 bits width.
43 * Lets arm timer for MCT_GT_COUNTER_STEP count and update internal G_CNT
44 * register during each event.
46 * Problem: both timers need to be implemented using MCT_XT_COUNTER_STEP because
47 * local timer contains two counters: TCNT and ICNT. TCNT == 0 -> ICNT--.
48 * IRQ is generated when ICNT riches zero. Implementation where TCNT == 0
49 * generates IRQs suffers from too frequently events. Better to have one
50 * uint64_t counter equal to TCNT*ICNT and arm ptimer.c for a minimum(TCNT*ICNT,
51 * MCT_GT_COUNTER_STEP); (yes, if target tunes ICNT * TCNT to be too low values,
52 * there is no way to avoid frequently events).
55 #include "hw/sysbus.h"
56 #include "qemu/timer.h"
57 #include "qemu/main-loop.h"
58 #include "qemu-common.h"
59 #include "hw/ptimer.h"
61 #include "hw/arm/exynos4210.h"
66 #define DPRINTF(fmt, ...) \
67 do { fprintf(stdout, "MCT: [%24s:%5d] " fmt, __func__, __LINE__, \
68 ## __VA_ARGS__); } while (0)
70 #define DPRINTF(fmt, ...) do {} while (0)
76 #define G_CNT_WSTAT 0x110
77 #define G_COMP0_L 0x200
78 #define G_COMP0_U 0x204
79 #define G_COMP0_ADD_INCR 0x208
80 #define G_COMP1_L 0x210
81 #define G_COMP1_U 0x214
82 #define G_COMP1_ADD_INCR 0x218
83 #define G_COMP2_L 0x220
84 #define G_COMP2_U 0x224
85 #define G_COMP2_ADD_INCR 0x228
86 #define G_COMP3_L 0x230
87 #define G_COMP3_U 0x234
88 #define G_COMP3_ADD_INCR 0x238
90 #define G_INT_CSTAT 0x244
91 #define G_INT_ENB 0x248
93 #define L0_TCNTB 0x300
94 #define L0_TCNTO 0x304
95 #define L0_ICNTB 0x308
96 #define L0_ICNTO 0x30C
97 #define L0_FRCNTB 0x310
98 #define L0_FRCNTO 0x314
100 #define L0_INT_CSTAT 0x330
101 #define L0_INT_ENB 0x334
102 #define L0_WSTAT 0x340
103 #define L1_TCNTB 0x400
104 #define L1_TCNTO 0x404
105 #define L1_ICNTB 0x408
106 #define L1_ICNTO 0x40C
107 #define L1_FRCNTB 0x410
108 #define L1_FRCNTO 0x414
109 #define L1_TCON 0x420
110 #define L1_INT_CSTAT 0x430
111 #define L1_INT_ENB 0x434
112 #define L1_WSTAT 0x440
114 #define MCT_CFG_GET_PRESCALER(x) ((x) & 0xFF)
115 #define MCT_CFG_GET_DIVIDER(x) (1 << ((x) >> 8 & 7))
117 #define GET_G_COMP_IDX(offset) (((offset) - G_COMP0_L) / 0x10)
118 #define GET_G_COMP_ADD_INCR_IDX(offset) (((offset) - G_COMP0_ADD_INCR) / 0x10)
120 #define G_COMP_L(x) (G_COMP0_L + (x) * 0x10)
121 #define G_COMP_U(x) (G_COMP0_U + (x) * 0x10)
123 #define G_COMP_ADD_INCR(x) (G_COMP0_ADD_INCR + (x) * 0x10)
126 #define G_TCON_COMP_ENABLE(x) (1 << 2 * (x))
127 #define G_TCON_AUTO_ICREMENT(x) (1 << (2 * (x) + 1))
128 #define G_TCON_TIMER_ENABLE (1 << 8)
130 #define G_INT_ENABLE(x) (1 << (x))
131 #define G_INT_CSTAT_COMP(x) (1 << (x))
133 #define G_CNT_WSTAT_L 1
134 #define G_CNT_WSTAT_U 2
136 #define G_WSTAT_COMP_L(x) (1 << 4 * (x))
137 #define G_WSTAT_COMP_U(x) (1 << ((4 * (x)) + 1))
138 #define G_WSTAT_COMP_ADDINCR(x) (1 << ((4 * (x)) + 2))
139 #define G_WSTAT_TCON_WRITE (1 << 16)
141 #define GET_L_TIMER_IDX(offset) ((((offset) & 0xF00) - L0_TCNTB) / 0x100)
142 #define GET_L_TIMER_CNT_REG_IDX(offset, lt_i) \
143 (((offset) - (L0_TCNTB + 0x100 * (lt_i))) >> 2)
145 #define L_ICNTB_MANUAL_UPDATE (1 << 31)
147 #define L_TCON_TICK_START (1)
148 #define L_TCON_INT_START (1 << 1)
149 #define L_TCON_INTERVAL_MODE (1 << 2)
150 #define L_TCON_FRC_START (1 << 3)
152 #define L_INT_CSTAT_INTCNT (1 << 0)
153 #define L_INT_CSTAT_FRCCNT (1 << 1)
155 #define L_INT_INTENB_ICNTEIE (1 << 0)
156 #define L_INT_INTENB_FRCEIE (1 << 1)
158 #define L_WSTAT_TCNTB_WRITE (1 << 0)
159 #define L_WSTAT_ICNTB_WRITE (1 << 1)
160 #define L_WSTAT_FRCCNTB_WRITE (1 << 2)
161 #define L_WSTAT_TCON_WRITE (1 << 3)
163 enum LocalTimerRegCntIndexes
{
175 #define MCT_SFR_SIZE 0x444
177 #define MCT_GT_CMP_NUM 4
179 #define MCT_GT_MAX_VAL UINT64_MAX
181 #define MCT_GT_COUNTER_STEP 0x100000000ULL
182 #define MCT_LT_COUNTER_STEP 0x100000000ULL
183 #define MCT_LT_CNT_LOW_LIMIT 0x100
187 qemu_irq irq
[MCT_GT_CMP_NUM
];
196 uint64_t comp
[MCT_GT_CMP_NUM
];
197 uint32_t comp_add_incr
[MCT_GT_CMP_NUM
];
200 uint64_t count
; /* Value FRC was armed with */
201 int32_t curr_comp
; /* Current comparator FRC is running to */
203 ptimer_state
*ptimer_frc
; /* FRC timer */
209 int id
; /* timer id */
210 qemu_irq irq
; /* local timer irq */
213 uint32_t cnt_run
; /* cnt timer is running */
214 uint32_t int_run
; /* int timer is running */
218 uint32_t tcntb
; /* initial value for TCNTB */
219 uint32_t icntb
; /* initial value for ICNTB */
222 uint64_t distance
; /* distance to count to the next event */
223 uint64_t progress
; /* progress when counting by steps */
224 uint64_t count
; /* count to arm timer with */
226 ptimer_state
*ptimer_tick
; /* timer for tick counter */
229 /* use ptimer.c to represent count down timer */
231 ptimer_state
*ptimer_frc
; /* timer for free running counter */
235 uint32_t cnt
[L_REG_CNT_AMOUNT
];
244 #define TYPE_EXYNOS4210_MCT "exynos4210.mct"
245 #define EXYNOS4210_MCT(obj) \
246 OBJECT_CHECK(Exynos4210MCTState, (obj), TYPE_EXYNOS4210_MCT)
248 typedef struct Exynos4210MCTState
{
249 SysBusDevice parent_obj
;
254 uint32_t reg_mct_cfg
;
256 Exynos4210MCTLT l_timer
[2];
257 Exynos4210MCTGT g_timer
;
259 uint32_t freq
; /* all timers tick frequency, TCLK */
260 } Exynos4210MCTState
;
263 static const VMStateDescription vmstate_tick_timer
= {
264 .name
= "exynos4210.mct.tick_timer",
266 .minimum_version_id
= 1,
267 .minimum_version_id_old
= 1,
268 .fields
= (VMStateField
[]) {
269 VMSTATE_UINT32(cnt_run
, struct tick_timer
),
270 VMSTATE_UINT32(int_run
, struct tick_timer
),
271 VMSTATE_UINT32(last_icnto
, struct tick_timer
),
272 VMSTATE_UINT32(last_tcnto
, struct tick_timer
),
273 VMSTATE_UINT32(tcntb
, struct tick_timer
),
274 VMSTATE_UINT32(icntb
, struct tick_timer
),
275 VMSTATE_UINT64(distance
, struct tick_timer
),
276 VMSTATE_UINT64(progress
, struct tick_timer
),
277 VMSTATE_UINT64(count
, struct tick_timer
),
278 VMSTATE_PTIMER(ptimer_tick
, struct tick_timer
),
279 VMSTATE_END_OF_LIST()
283 static const VMStateDescription vmstate_lregs
= {
284 .name
= "exynos4210.mct.lregs",
286 .minimum_version_id
= 1,
287 .minimum_version_id_old
= 1,
288 .fields
= (VMStateField
[]) {
289 VMSTATE_UINT32_ARRAY(cnt
, struct lregs
, L_REG_CNT_AMOUNT
),
290 VMSTATE_UINT32(tcon
, struct lregs
),
291 VMSTATE_UINT32(int_cstat
, struct lregs
),
292 VMSTATE_UINT32(int_enb
, struct lregs
),
293 VMSTATE_UINT32(wstat
, struct lregs
),
294 VMSTATE_END_OF_LIST()
298 static const VMStateDescription vmstate_exynos4210_mct_lt
= {
299 .name
= "exynos4210.mct.lt",
301 .minimum_version_id
= 1,
302 .minimum_version_id_old
= 1,
303 .fields
= (VMStateField
[]) {
304 VMSTATE_INT32(id
, Exynos4210MCTLT
),
305 VMSTATE_STRUCT(tick_timer
, Exynos4210MCTLT
, 0,
308 VMSTATE_PTIMER(ptimer_frc
, Exynos4210MCTLT
),
309 VMSTATE_STRUCT(reg
, Exynos4210MCTLT
, 0,
312 VMSTATE_END_OF_LIST()
316 static const VMStateDescription vmstate_gregs
= {
317 .name
= "exynos4210.mct.lregs",
319 .minimum_version_id
= 1,
320 .minimum_version_id_old
= 1,
321 .fields
= (VMStateField
[]) {
322 VMSTATE_UINT64(cnt
, struct gregs
),
323 VMSTATE_UINT32(cnt_wstat
, struct gregs
),
324 VMSTATE_UINT32(tcon
, struct gregs
),
325 VMSTATE_UINT32(int_cstat
, struct gregs
),
326 VMSTATE_UINT32(int_enb
, struct gregs
),
327 VMSTATE_UINT32(wstat
, struct gregs
),
328 VMSTATE_UINT64_ARRAY(comp
, struct gregs
, MCT_GT_CMP_NUM
),
329 VMSTATE_UINT32_ARRAY(comp_add_incr
, struct gregs
,
331 VMSTATE_END_OF_LIST()
335 static const VMStateDescription vmstate_exynos4210_mct_gt
= {
336 .name
= "exynos4210.mct.lt",
338 .minimum_version_id
= 1,
339 .minimum_version_id_old
= 1,
340 .fields
= (VMStateField
[]) {
341 VMSTATE_STRUCT(reg
, Exynos4210MCTGT
, 0, vmstate_gregs
,
343 VMSTATE_UINT64(count
, Exynos4210MCTGT
),
344 VMSTATE_INT32(curr_comp
, Exynos4210MCTGT
),
345 VMSTATE_PTIMER(ptimer_frc
, Exynos4210MCTGT
),
346 VMSTATE_END_OF_LIST()
350 static const VMStateDescription vmstate_exynos4210_mct_state
= {
351 .name
= "exynos4210.mct",
353 .minimum_version_id
= 1,
354 .minimum_version_id_old
= 1,
355 .fields
= (VMStateField
[]) {
356 VMSTATE_UINT32(reg_mct_cfg
, Exynos4210MCTState
),
357 VMSTATE_STRUCT_ARRAY(l_timer
, Exynos4210MCTState
, 2, 0,
358 vmstate_exynos4210_mct_lt
, Exynos4210MCTLT
),
359 VMSTATE_STRUCT(g_timer
, Exynos4210MCTState
, 0,
360 vmstate_exynos4210_mct_gt
, Exynos4210MCTGT
),
361 VMSTATE_UINT32(freq
, Exynos4210MCTState
),
362 VMSTATE_END_OF_LIST()
366 static void exynos4210_mct_update_freq(Exynos4210MCTState
*s
);
369 * Set counter of FRC global timer.
371 static void exynos4210_gfrc_set_count(Exynos4210MCTGT
*s
, uint64_t count
)
374 DPRINTF("global timer frc set count 0x%llx\n", count
);
375 ptimer_set_count(s
->ptimer_frc
, count
);
379 * Get counter of FRC global timer.
381 static uint64_t exynos4210_gfrc_get_count(Exynos4210MCTGT
*s
)
384 count
= ptimer_get_count(s
->ptimer_frc
);
385 count
= s
->count
- count
;
386 return s
->reg
.cnt
+ count
;
390 * Stop global FRC timer
392 static void exynos4210_gfrc_stop(Exynos4210MCTGT
*s
)
394 DPRINTF("global timer frc stop\n");
396 ptimer_stop(s
->ptimer_frc
);
400 * Start global FRC timer
402 static void exynos4210_gfrc_start(Exynos4210MCTGT
*s
)
404 DPRINTF("global timer frc start\n");
406 ptimer_run(s
->ptimer_frc
, 1);
410 * Find next nearest Comparator. If current Comparator value equals to other
411 * Comparator value, skip them both
413 static int32_t exynos4210_gcomp_find(Exynos4210MCTState
*s
)
422 uint64_t distance_min
;
426 gfrc
= exynos4210_gfrc_get_count(&s
->g_timer
);
429 distance_min
= UINT64_MAX
;
430 comp_i
= MCT_GT_CMP_NUM
;
431 min_comp_i
= MCT_GT_CMP_NUM
;
434 /* lookup for nearest comparator */
435 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
437 if (s
->g_timer
.reg
.tcon
& G_TCON_COMP_ENABLE(i
)) {
441 if (s
->g_timer
.reg
.comp
[i
] > gfrc
) {
442 /* Comparator is upper then FRC */
443 distance
= s
->g_timer
.reg
.comp
[i
] - gfrc
;
445 if (distance
<= distance_min
) {
446 distance_min
= distance
;
450 /* Comparator is below FRC, find the smallest */
452 if (s
->g_timer
.reg
.comp
[i
] <= min
) {
453 min
= s
->g_timer
.reg
.comp
[i
];
461 /* All Comparators disabled */
463 } else if (comp_i
< MCT_GT_CMP_NUM
) {
464 /* Found upper Comparator */
467 /* All Comparators are below or equal to FRC */
471 DPRINTF("found comparator %d: comp 0x%llx distance 0x%llx, gfrc 0x%llx\n",
473 s
->g_timer
.reg
.comp
[res
],
481 * Get distance to nearest Comparator
483 static uint64_t exynos4210_gcomp_get_distance(Exynos4210MCTState
*s
, int32_t id
)
486 /* no enabled Comparators, choose max distance */
487 return MCT_GT_COUNTER_STEP
;
489 if (s
->g_timer
.reg
.comp
[id
] - s
->g_timer
.reg
.cnt
< MCT_GT_COUNTER_STEP
) {
490 return s
->g_timer
.reg
.comp
[id
] - s
->g_timer
.reg
.cnt
;
492 return MCT_GT_COUNTER_STEP
;
497 * Restart global FRC timer
499 static void exynos4210_gfrc_restart(Exynos4210MCTState
*s
)
503 exynos4210_gfrc_stop(&s
->g_timer
);
505 s
->g_timer
.curr_comp
= exynos4210_gcomp_find(s
);
507 distance
= exynos4210_gcomp_get_distance(s
, s
->g_timer
.curr_comp
);
509 if (distance
> MCT_GT_COUNTER_STEP
|| !distance
) {
510 distance
= MCT_GT_COUNTER_STEP
;
513 exynos4210_gfrc_set_count(&s
->g_timer
, distance
);
514 exynos4210_gfrc_start(&s
->g_timer
);
518 * Raise global timer CMP IRQ
520 static void exynos4210_gcomp_raise_irq(void *opaque
, uint32_t id
)
522 Exynos4210MCTGT
*s
= opaque
;
524 /* If CSTAT is pending and IRQ is enabled */
525 if ((s
->reg
.int_cstat
& G_INT_CSTAT_COMP(id
)) &&
526 (s
->reg
.int_enb
& G_INT_ENABLE(id
))) {
527 DPRINTF("gcmp timer[%d] IRQ\n", id
);
528 qemu_irq_raise(s
->irq
[id
]);
533 * Lower global timer CMP IRQ
535 static void exynos4210_gcomp_lower_irq(void *opaque
, uint32_t id
)
537 Exynos4210MCTGT
*s
= opaque
;
538 qemu_irq_lower(s
->irq
[id
]);
542 * Global timer FRC event handler.
543 * Each event occurs when internal counter reaches counter + MCT_GT_COUNTER_STEP
544 * Every time we arm global FRC timer to count for MCT_GT_COUNTER_STEP value
546 static void exynos4210_gfrc_event(void *opaque
)
548 Exynos4210MCTState
*s
= (Exynos4210MCTState
*)opaque
;
554 s
->g_timer
.reg
.cnt
+= s
->g_timer
.count
;
556 /* Process all comparators */
557 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
559 if (s
->g_timer
.reg
.cnt
== s
->g_timer
.reg
.comp
[i
]) {
560 /* reached nearest comparator */
562 s
->g_timer
.reg
.int_cstat
|= G_INT_CSTAT_COMP(i
);
565 if (s
->g_timer
.reg
.tcon
& G_TCON_AUTO_ICREMENT(i
)) {
566 s
->g_timer
.reg
.comp
[i
] += s
->g_timer
.reg
.comp_add_incr
[i
];
570 exynos4210_gcomp_raise_irq(&s
->g_timer
, i
);
574 /* Reload FRC to reach nearest comparator */
575 s
->g_timer
.curr_comp
= exynos4210_gcomp_find(s
);
576 distance
= exynos4210_gcomp_get_distance(s
, s
->g_timer
.curr_comp
);
577 if (distance
> MCT_GT_COUNTER_STEP
|| !distance
) {
578 distance
= MCT_GT_COUNTER_STEP
;
580 exynos4210_gfrc_set_count(&s
->g_timer
, distance
);
582 exynos4210_gfrc_start(&s
->g_timer
);
586 * Get counter of FRC local timer.
588 static uint64_t exynos4210_lfrc_get_count(Exynos4210MCTLT
*s
)
590 return ptimer_get_count(s
->ptimer_frc
);
594 * Set counter of FRC local timer.
596 static void exynos4210_lfrc_update_count(Exynos4210MCTLT
*s
)
598 if (!s
->reg
.cnt
[L_REG_CNT_FRCCNTB
]) {
599 ptimer_set_count(s
->ptimer_frc
, MCT_LT_COUNTER_STEP
);
601 ptimer_set_count(s
->ptimer_frc
, s
->reg
.cnt
[L_REG_CNT_FRCCNTB
]);
606 * Start local FRC timer
608 static void exynos4210_lfrc_start(Exynos4210MCTLT
*s
)
610 ptimer_run(s
->ptimer_frc
, 1);
614 * Stop local FRC timer
616 static void exynos4210_lfrc_stop(Exynos4210MCTLT
*s
)
618 ptimer_stop(s
->ptimer_frc
);
622 * Local timer free running counter tick handler
624 static void exynos4210_lfrc_event(void *opaque
)
626 Exynos4210MCTLT
* s
= (Exynos4210MCTLT
*)opaque
;
628 /* local frc expired */
632 s
->reg
.int_cstat
|= L_INT_CSTAT_FRCCNT
;
634 /* update frc counter */
635 exynos4210_lfrc_update_count(s
);
638 if (s
->reg
.int_enb
& L_INT_INTENB_FRCEIE
) {
639 qemu_irq_raise(s
->irq
);
642 /* we reached here, this means that timer is enabled */
643 exynos4210_lfrc_start(s
);
646 static uint32_t exynos4210_ltick_int_get_cnto(struct tick_timer
*s
);
647 static uint32_t exynos4210_ltick_cnt_get_cnto(struct tick_timer
*s
);
648 static void exynos4210_ltick_recalc_count(struct tick_timer
*s
);
651 * Action on enabling local tick int timer
653 static void exynos4210_ltick_int_start(struct tick_timer
*s
)
661 * Action on disabling local tick int timer
663 static void exynos4210_ltick_int_stop(struct tick_timer
*s
)
666 s
->last_icnto
= exynos4210_ltick_int_get_cnto(s
);
672 * Get count for INT timer
674 static uint32_t exynos4210_ltick_int_get_cnto(struct tick_timer
*s
)
680 uint64_t cur_progress
;
682 count
= ptimer_get_count(s
->ptimer_tick
);
684 /* timer is still counting, called not from event */
685 counted
= s
->count
- ptimer_get_count(s
->ptimer_tick
);
686 cur_progress
= s
->progress
+ counted
;
688 /* timer expired earlier */
689 cur_progress
= s
->progress
;
692 remain
= s
->distance
- cur_progress
;
695 /* INT is stopped. */
696 icnto
= s
->last_icnto
;
698 /* Both are counting */
699 icnto
= remain
/ s
->tcntb
;
706 * Start local tick cnt timer.
708 static void exynos4210_ltick_cnt_start(struct tick_timer
*s
)
712 exynos4210_ltick_recalc_count(s
);
713 ptimer_set_count(s
->ptimer_tick
, s
->count
);
714 ptimer_run(s
->ptimer_tick
, 1);
721 * Stop local tick cnt timer.
723 static void exynos4210_ltick_cnt_stop(struct tick_timer
*s
)
727 s
->last_tcnto
= exynos4210_ltick_cnt_get_cnto(s
);
730 exynos4210_ltick_int_stop(s
);
733 ptimer_stop(s
->ptimer_tick
);
740 * Get counter for CNT timer
742 static uint32_t exynos4210_ltick_cnt_get_cnto(struct tick_timer
*s
)
749 uint64_t cur_progress
;
751 count
= ptimer_get_count(s
->ptimer_tick
);
753 /* timer is still counting, called not from event */
754 counted
= s
->count
- ptimer_get_count(s
->ptimer_tick
);
755 cur_progress
= s
->progress
+ counted
;
757 /* timer expired earlier */
758 cur_progress
= s
->progress
;
761 remain
= s
->distance
- cur_progress
;
764 /* Both are stopped. */
765 tcnto
= s
->last_tcnto
;
766 } else if (!s
->int_run
) {
767 /* INT counter is stopped, progress is by CNT timer */
768 tcnto
= remain
% s
->tcntb
;
770 /* Both are counting */
771 icnto
= remain
/ s
->tcntb
;
773 tcnto
= remain
% (icnto
* s
->tcntb
);
775 tcnto
= remain
% s
->tcntb
;
783 * Set new values of counters for CNT and INT timers
785 static void exynos4210_ltick_set_cntb(struct tick_timer
*s
, uint32_t new_cnt
,
788 uint32_t cnt_stopped
= 0;
789 uint32_t int_stopped
= 0;
792 exynos4210_ltick_cnt_stop(s
);
797 exynos4210_ltick_int_stop(s
);
801 s
->tcntb
= new_cnt
+ 1;
802 s
->icntb
= new_int
+ 1;
805 exynos4210_ltick_cnt_start(s
);
808 exynos4210_ltick_int_start(s
);
814 * Calculate new counter value for tick timer
816 static void exynos4210_ltick_recalc_count(struct tick_timer
*s
)
820 if ((s
->cnt_run
&& s
->last_tcnto
) || (s
->int_run
&& s
->last_icnto
)) {
822 * one or both timers run and not counted to the end;
823 * distance is not passed, recalculate with last_tcnto * last_icnto
827 to_count
= s
->last_tcnto
* s
->last_icnto
;
829 to_count
= s
->last_icnto
;
832 /* distance is passed, recalculate with tcnto * icnto */
834 s
->distance
= s
->tcntb
* s
->icntb
;
836 s
->distance
= s
->tcntb
;
839 to_count
= s
->distance
;
843 if (to_count
> MCT_LT_COUNTER_STEP
) {
845 s
->count
= MCT_LT_COUNTER_STEP
;
852 * Initialize tick_timer
854 static void exynos4210_ltick_timer_init(struct tick_timer
*s
)
856 exynos4210_ltick_int_stop(s
);
857 exynos4210_ltick_cnt_stop(s
);
868 * Raises when abstract tick_timer expires.
870 static void exynos4210_ltick_timer_event(struct tick_timer
*s
)
872 s
->progress
+= s
->count
;
876 * Local timer tick counter handler.
877 * Don't use reloaded timers. If timer counter = zero
878 * then handler called but after handler finished no
879 * timer reload occurs.
881 static void exynos4210_ltick_event(void *opaque
)
883 Exynos4210MCTLT
* s
= (Exynos4210MCTLT
*)opaque
;
887 static uint64_t time1
[2] = {0};
888 static uint64_t time2
[2] = {0};
891 /* Call tick_timer event handler, it will update its tcntb and icntb. */
892 exynos4210_ltick_timer_event(&s
->tick_timer
);
894 /* get tick_timer cnt */
895 tcnto
= exynos4210_ltick_cnt_get_cnto(&s
->tick_timer
);
897 /* get tick_timer int */
898 icnto
= exynos4210_ltick_int_get_cnto(&s
->tick_timer
);
900 /* raise IRQ if needed */
901 if (!icnto
&& s
->reg
.tcon
& L_TCON_INT_START
) {
902 /* INT counter enabled and expired */
904 s
->reg
.int_cstat
|= L_INT_CSTAT_INTCNT
;
906 /* raise interrupt if enabled */
907 if (s
->reg
.int_enb
& L_INT_INTENB_ICNTEIE
) {
909 time2
[s
->id
] = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
910 DPRINTF("local timer[%d] IRQ: %llx\n", s
->id
,
911 time2
[s
->id
] - time1
[s
->id
]);
912 time1
[s
->id
] = time2
[s
->id
];
914 qemu_irq_raise(s
->irq
);
918 if (s
->reg
.tcon
& L_TCON_INTERVAL_MODE
) {
919 exynos4210_ltick_set_cntb(&s
->tick_timer
,
920 s
->reg
.cnt
[L_REG_CNT_TCNTB
],
921 s
->reg
.cnt
[L_REG_CNT_ICNTB
]);
926 exynos4210_ltick_set_cntb(&s
->tick_timer
,
927 s
->reg
.cnt
[L_REG_CNT_TCNTB
],
932 /* start tick_timer cnt */
933 exynos4210_ltick_cnt_start(&s
->tick_timer
);
935 /* start tick_timer int */
936 exynos4210_ltick_int_start(&s
->tick_timer
);
939 /* update timer frequency */
940 static void exynos4210_mct_update_freq(Exynos4210MCTState
*s
)
942 uint32_t freq
= s
->freq
;
944 ((MCT_CFG_GET_PRESCALER(s
->reg_mct_cfg
)+1) *
945 MCT_CFG_GET_DIVIDER(s
->reg_mct_cfg
));
947 if (freq
!= s
->freq
) {
948 DPRINTF("freq=%dHz\n", s
->freq
);
951 ptimer_set_freq(s
->g_timer
.ptimer_frc
, s
->freq
);
954 ptimer_set_freq(s
->l_timer
[0].tick_timer
.ptimer_tick
, s
->freq
);
955 ptimer_set_freq(s
->l_timer
[0].ptimer_frc
, s
->freq
);
956 ptimer_set_freq(s
->l_timer
[1].tick_timer
.ptimer_tick
, s
->freq
);
957 ptimer_set_freq(s
->l_timer
[1].ptimer_frc
, s
->freq
);
961 /* set defaul_timer values for all fields */
962 static void exynos4210_mct_reset(DeviceState
*d
)
964 Exynos4210MCTState
*s
= EXYNOS4210_MCT(d
);
970 memset(&s
->g_timer
.reg
, 0, sizeof(s
->g_timer
.reg
));
971 exynos4210_gfrc_stop(&s
->g_timer
);
974 memset(s
->l_timer
[0].reg
.cnt
, 0, sizeof(s
->l_timer
[0].reg
.cnt
));
975 memset(s
->l_timer
[1].reg
.cnt
, 0, sizeof(s
->l_timer
[1].reg
.cnt
));
976 for (i
= 0; i
< 2; i
++) {
977 s
->l_timer
[i
].reg
.int_cstat
= 0;
978 s
->l_timer
[i
].reg
.int_enb
= 0;
979 s
->l_timer
[i
].reg
.tcon
= 0;
980 s
->l_timer
[i
].reg
.wstat
= 0;
981 s
->l_timer
[i
].tick_timer
.count
= 0;
982 s
->l_timer
[i
].tick_timer
.distance
= 0;
983 s
->l_timer
[i
].tick_timer
.progress
= 0;
984 ptimer_stop(s
->l_timer
[i
].ptimer_frc
);
986 exynos4210_ltick_timer_init(&s
->l_timer
[i
].tick_timer
);
989 exynos4210_mct_update_freq(s
);
993 /* Multi Core Timer read */
994 static uint64_t exynos4210_mct_read(void *opaque
, hwaddr offset
,
997 Exynos4210MCTState
*s
= (Exynos4210MCTState
*)opaque
;
1007 value
= s
->reg_mct_cfg
;
1010 case G_CNT_L
: case G_CNT_U
:
1011 shift
= 8 * (offset
& 0x4);
1012 count
= exynos4210_gfrc_get_count(&s
->g_timer
);
1013 value
= UINT32_MAX
& (count
>> shift
);
1014 DPRINTF("read FRC=0x%llx\n", count
);
1018 value
= s
->g_timer
.reg
.cnt_wstat
;
1021 case G_COMP_L(0): case G_COMP_L(1): case G_COMP_L(2): case G_COMP_L(3):
1022 case G_COMP_U(0): case G_COMP_U(1): case G_COMP_U(2): case G_COMP_U(3):
1023 index
= GET_G_COMP_IDX(offset
);
1024 shift
= 8 * (offset
& 0x4);
1025 value
= UINT32_MAX
& (s
->g_timer
.reg
.comp
[index
] >> shift
);
1029 value
= s
->g_timer
.reg
.tcon
;
1033 value
= s
->g_timer
.reg
.int_cstat
;
1037 value
= s
->g_timer
.reg
.int_enb
;
1040 value
= s
->g_timer
.reg
.wstat
;
1043 case G_COMP0_ADD_INCR
: case G_COMP1_ADD_INCR
:
1044 case G_COMP2_ADD_INCR
: case G_COMP3_ADD_INCR
:
1045 value
= s
->g_timer
.reg
.comp_add_incr
[GET_G_COMP_ADD_INCR_IDX(offset
)];
1049 case L0_TCNTB
: case L0_ICNTB
: case L0_FRCNTB
:
1050 case L1_TCNTB
: case L1_ICNTB
: case L1_FRCNTB
:
1051 lt_i
= GET_L_TIMER_IDX(offset
);
1052 index
= GET_L_TIMER_CNT_REG_IDX(offset
, lt_i
);
1053 value
= s
->l_timer
[lt_i
].reg
.cnt
[index
];
1056 case L0_TCNTO
: case L1_TCNTO
:
1057 lt_i
= GET_L_TIMER_IDX(offset
);
1059 value
= exynos4210_ltick_cnt_get_cnto(&s
->l_timer
[lt_i
].tick_timer
);
1060 DPRINTF("local timer[%d] read TCNTO %x\n", lt_i
, value
);
1063 case L0_ICNTO
: case L1_ICNTO
:
1064 lt_i
= GET_L_TIMER_IDX(offset
);
1066 value
= exynos4210_ltick_int_get_cnto(&s
->l_timer
[lt_i
].tick_timer
);
1067 DPRINTF("local timer[%d] read ICNTO %x\n", lt_i
, value
);
1070 case L0_FRCNTO
: case L1_FRCNTO
:
1071 lt_i
= GET_L_TIMER_IDX(offset
);
1073 value
= exynos4210_lfrc_get_count(&s
->l_timer
[lt_i
]);
1077 case L0_TCON
: case L1_TCON
:
1078 lt_i
= ((offset
& 0xF00) - L0_TCNTB
) / 0x100;
1079 value
= s
->l_timer
[lt_i
].reg
.tcon
;
1082 case L0_INT_CSTAT
: case L1_INT_CSTAT
:
1083 lt_i
= ((offset
& 0xF00) - L0_TCNTB
) / 0x100;
1084 value
= s
->l_timer
[lt_i
].reg
.int_cstat
;
1087 case L0_INT_ENB
: case L1_INT_ENB
:
1088 lt_i
= ((offset
& 0xF00) - L0_TCNTB
) / 0x100;
1089 value
= s
->l_timer
[lt_i
].reg
.int_enb
;
1092 case L0_WSTAT
: case L1_WSTAT
:
1093 lt_i
= ((offset
& 0xF00) - L0_TCNTB
) / 0x100;
1094 value
= s
->l_timer
[lt_i
].reg
.wstat
;
1098 hw_error("exynos4210.mct: bad read offset "
1099 TARGET_FMT_plx
"\n", offset
);
1106 static void exynos4210_mct_write(void *opaque
, hwaddr offset
,
1107 uint64_t value
, unsigned size
)
1109 Exynos4210MCTState
*s
= (Exynos4210MCTState
*)opaque
;
1110 int index
; /* index in buffer which represents register set */
1117 static uint32_t icntb_max
[2] = {0};
1118 static uint32_t icntb_min
[2] = {UINT32_MAX
, UINT32_MAX
};
1119 static uint32_t tcntb_max
[2] = {0};
1120 static uint32_t tcntb_min
[2] = {UINT32_MAX
, UINT32_MAX
};
1123 new_frc
= s
->g_timer
.reg
.cnt
;
1128 s
->reg_mct_cfg
= value
;
1129 exynos4210_mct_update_freq(s
);
1134 if (offset
== G_CNT_L
) {
1136 DPRINTF("global timer write to reg.cntl %llx\n", value
);
1138 new_frc
= (s
->g_timer
.reg
.cnt
& (uint64_t)UINT32_MAX
<< 32) + value
;
1139 s
->g_timer
.reg
.cnt_wstat
|= G_CNT_WSTAT_L
;
1141 if (offset
== G_CNT_U
) {
1143 DPRINTF("global timer write to reg.cntu %llx\n", value
);
1145 new_frc
= (s
->g_timer
.reg
.cnt
& UINT32_MAX
) +
1146 ((uint64_t)value
<< 32);
1147 s
->g_timer
.reg
.cnt_wstat
|= G_CNT_WSTAT_U
;
1150 s
->g_timer
.reg
.cnt
= new_frc
;
1151 exynos4210_gfrc_restart(s
);
1155 s
->g_timer
.reg
.cnt_wstat
&= ~(value
);
1158 case G_COMP_L(0): case G_COMP_L(1): case G_COMP_L(2): case G_COMP_L(3):
1159 case G_COMP_U(0): case G_COMP_U(1): case G_COMP_U(2): case G_COMP_U(3):
1160 index
= GET_G_COMP_IDX(offset
);
1161 shift
= 8 * (offset
& 0x4);
1162 s
->g_timer
.reg
.comp
[index
] =
1163 (s
->g_timer
.reg
.comp
[index
] &
1164 (((uint64_t)UINT32_MAX
<< 32) >> shift
)) +
1167 DPRINTF("comparator %d write 0x%llx val << %d\n", index
, value
, shift
);
1170 s
->g_timer
.reg
.wstat
|= G_WSTAT_COMP_U(index
);
1172 s
->g_timer
.reg
.wstat
|= G_WSTAT_COMP_L(index
);
1175 exynos4210_gfrc_restart(s
);
1179 old_val
= s
->g_timer
.reg
.tcon
;
1180 s
->g_timer
.reg
.tcon
= value
;
1181 s
->g_timer
.reg
.wstat
|= G_WSTAT_TCON_WRITE
;
1183 DPRINTF("global timer write to reg.g_tcon %llx\n", value
);
1185 /* Start FRC if transition from disabled to enabled */
1186 if ((value
& G_TCON_TIMER_ENABLE
) > (old_val
&
1187 G_TCON_TIMER_ENABLE
)) {
1188 exynos4210_gfrc_start(&s
->g_timer
);
1190 if ((value
& G_TCON_TIMER_ENABLE
) < (old_val
&
1191 G_TCON_TIMER_ENABLE
)) {
1192 exynos4210_gfrc_stop(&s
->g_timer
);
1195 /* Start CMP if transition from disabled to enabled */
1196 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
1197 if ((value
& G_TCON_COMP_ENABLE(i
)) != (old_val
&
1198 G_TCON_COMP_ENABLE(i
))) {
1199 exynos4210_gfrc_restart(s
);
1205 s
->g_timer
.reg
.int_cstat
&= ~(value
);
1206 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
1207 if (value
& G_INT_CSTAT_COMP(i
)) {
1208 exynos4210_gcomp_lower_irq(&s
->g_timer
, i
);
1215 /* Raise IRQ if transition from disabled to enabled and CSTAT pending */
1216 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
1217 if ((value
& G_INT_ENABLE(i
)) > (s
->g_timer
.reg
.tcon
&
1219 if (s
->g_timer
.reg
.int_cstat
& G_INT_CSTAT_COMP(i
)) {
1220 exynos4210_gcomp_raise_irq(&s
->g_timer
, i
);
1224 if ((value
& G_INT_ENABLE(i
)) < (s
->g_timer
.reg
.tcon
&
1226 exynos4210_gcomp_lower_irq(&s
->g_timer
, i
);
1230 DPRINTF("global timer INT enable %llx\n", value
);
1231 s
->g_timer
.reg
.int_enb
= value
;
1235 s
->g_timer
.reg
.wstat
&= ~(value
);
1238 case G_COMP0_ADD_INCR
: case G_COMP1_ADD_INCR
:
1239 case G_COMP2_ADD_INCR
: case G_COMP3_ADD_INCR
:
1240 index
= GET_G_COMP_ADD_INCR_IDX(offset
);
1241 s
->g_timer
.reg
.comp_add_incr
[index
] = value
;
1242 s
->g_timer
.reg
.wstat
|= G_WSTAT_COMP_ADDINCR(index
);
1246 case L0_TCON
: case L1_TCON
:
1247 lt_i
= GET_L_TIMER_IDX(offset
);
1248 old_val
= s
->l_timer
[lt_i
].reg
.tcon
;
1250 s
->l_timer
[lt_i
].reg
.wstat
|= L_WSTAT_TCON_WRITE
;
1251 s
->l_timer
[lt_i
].reg
.tcon
= value
;
1253 /* Stop local CNT */
1254 if ((value
& L_TCON_TICK_START
) <
1255 (old_val
& L_TCON_TICK_START
)) {
1256 DPRINTF("local timer[%d] stop cnt\n", lt_i
);
1257 exynos4210_ltick_cnt_stop(&s
->l_timer
[lt_i
].tick_timer
);
1260 /* Stop local INT */
1261 if ((value
& L_TCON_INT_START
) <
1262 (old_val
& L_TCON_INT_START
)) {
1263 DPRINTF("local timer[%d] stop int\n", lt_i
);
1264 exynos4210_ltick_int_stop(&s
->l_timer
[lt_i
].tick_timer
);
1267 /* Start local CNT */
1268 if ((value
& L_TCON_TICK_START
) >
1269 (old_val
& L_TCON_TICK_START
)) {
1270 DPRINTF("local timer[%d] start cnt\n", lt_i
);
1271 exynos4210_ltick_cnt_start(&s
->l_timer
[lt_i
].tick_timer
);
1274 /* Start local INT */
1275 if ((value
& L_TCON_INT_START
) >
1276 (old_val
& L_TCON_INT_START
)) {
1277 DPRINTF("local timer[%d] start int\n", lt_i
);
1278 exynos4210_ltick_int_start(&s
->l_timer
[lt_i
].tick_timer
);
1281 /* Start or Stop local FRC if TCON changed */
1282 if ((value
& L_TCON_FRC_START
) >
1283 (s
->l_timer
[lt_i
].reg
.tcon
& L_TCON_FRC_START
)) {
1284 DPRINTF("local timer[%d] start frc\n", lt_i
);
1285 exynos4210_lfrc_start(&s
->l_timer
[lt_i
]);
1287 if ((value
& L_TCON_FRC_START
) <
1288 (s
->l_timer
[lt_i
].reg
.tcon
& L_TCON_FRC_START
)) {
1289 DPRINTF("local timer[%d] stop frc\n", lt_i
);
1290 exynos4210_lfrc_stop(&s
->l_timer
[lt_i
]);
1294 case L0_TCNTB
: case L1_TCNTB
:
1296 lt_i
= GET_L_TIMER_IDX(offset
);
1297 index
= GET_L_TIMER_CNT_REG_IDX(offset
, lt_i
);
1300 * TCNTB is updated to internal register only after CNT expired.
1301 * Due to this we should reload timer to nearest moment when CNT is
1302 * expired and then in event handler update tcntb to new TCNTB value.
1304 exynos4210_ltick_set_cntb(&s
->l_timer
[lt_i
].tick_timer
, value
,
1305 s
->l_timer
[lt_i
].tick_timer
.icntb
);
1307 s
->l_timer
[lt_i
].reg
.wstat
|= L_WSTAT_TCNTB_WRITE
;
1308 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_TCNTB
] = value
;
1311 if (tcntb_min
[lt_i
] > value
) {
1312 tcntb_min
[lt_i
] = value
;
1314 if (tcntb_max
[lt_i
] < value
) {
1315 tcntb_max
[lt_i
] = value
;
1317 DPRINTF("local timer[%d] TCNTB write %llx; max=%x, min=%x\n",
1318 lt_i
, value
, tcntb_max
[lt_i
], tcntb_min
[lt_i
]);
1322 case L0_ICNTB
: case L1_ICNTB
:
1324 lt_i
= GET_L_TIMER_IDX(offset
);
1325 index
= GET_L_TIMER_CNT_REG_IDX(offset
, lt_i
);
1327 s
->l_timer
[lt_i
].reg
.wstat
|= L_WSTAT_ICNTB_WRITE
;
1328 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_ICNTB
] = value
&
1329 ~L_ICNTB_MANUAL_UPDATE
;
1332 * We need to avoid too small values for TCNTB*ICNTB. If not, IRQ event
1333 * could raise too fast disallowing QEMU to execute target code.
1335 if (s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_ICNTB
] *
1336 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_TCNTB
] < MCT_LT_CNT_LOW_LIMIT
) {
1337 if (!s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_TCNTB
]) {
1338 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_ICNTB
] =
1339 MCT_LT_CNT_LOW_LIMIT
;
1341 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_ICNTB
] =
1342 MCT_LT_CNT_LOW_LIMIT
/
1343 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_TCNTB
];
1347 if (value
& L_ICNTB_MANUAL_UPDATE
) {
1348 exynos4210_ltick_set_cntb(&s
->l_timer
[lt_i
].tick_timer
,
1349 s
->l_timer
[lt_i
].tick_timer
.tcntb
,
1350 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_ICNTB
]);
1354 if (icntb_min
[lt_i
] > value
) {
1355 icntb_min
[lt_i
] = value
;
1357 if (icntb_max
[lt_i
] < value
) {
1358 icntb_max
[lt_i
] = value
;
1360 DPRINTF("local timer[%d] ICNTB write %llx; max=%x, min=%x\n\n",
1361 lt_i
, value
, icntb_max
[lt_i
], icntb_min
[lt_i
]);
1365 case L0_FRCNTB
: case L1_FRCNTB
:
1367 lt_i
= GET_L_TIMER_IDX(offset
);
1368 index
= GET_L_TIMER_CNT_REG_IDX(offset
, lt_i
);
1370 DPRINTF("local timer[%d] FRCNTB write %llx\n", lt_i
, value
);
1372 s
->l_timer
[lt_i
].reg
.wstat
|= L_WSTAT_FRCCNTB_WRITE
;
1373 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_FRCCNTB
] = value
;
1377 case L0_TCNTO
: case L1_TCNTO
:
1378 case L0_ICNTO
: case L1_ICNTO
:
1379 case L0_FRCNTO
: case L1_FRCNTO
:
1380 fprintf(stderr
, "\n[exynos4210.mct: write to RO register "
1381 TARGET_FMT_plx
"]\n\n", offset
);
1384 case L0_INT_CSTAT
: case L1_INT_CSTAT
:
1385 lt_i
= GET_L_TIMER_IDX(offset
);
1387 DPRINTF("local timer[%d] CSTAT write %llx\n", lt_i
, value
);
1389 s
->l_timer
[lt_i
].reg
.int_cstat
&= ~value
;
1390 if (!s
->l_timer
[lt_i
].reg
.int_cstat
) {
1391 qemu_irq_lower(s
->l_timer
[lt_i
].irq
);
1395 case L0_INT_ENB
: case L1_INT_ENB
:
1396 lt_i
= GET_L_TIMER_IDX(offset
);
1397 old_val
= s
->l_timer
[lt_i
].reg
.int_enb
;
1399 /* Raise Local timer IRQ if cstat is pending */
1400 if ((value
& L_INT_INTENB_ICNTEIE
) > (old_val
& L_INT_INTENB_ICNTEIE
)) {
1401 if (s
->l_timer
[lt_i
].reg
.int_cstat
& L_INT_CSTAT_INTCNT
) {
1402 qemu_irq_raise(s
->l_timer
[lt_i
].irq
);
1406 s
->l_timer
[lt_i
].reg
.int_enb
= value
;
1410 case L0_WSTAT
: case L1_WSTAT
:
1411 lt_i
= GET_L_TIMER_IDX(offset
);
1413 s
->l_timer
[lt_i
].reg
.wstat
&= ~value
;
1417 hw_error("exynos4210.mct: bad write offset "
1418 TARGET_FMT_plx
"\n", offset
);
1423 static const MemoryRegionOps exynos4210_mct_ops
= {
1424 .read
= exynos4210_mct_read
,
1425 .write
= exynos4210_mct_write
,
1426 .endianness
= DEVICE_NATIVE_ENDIAN
,
1430 static int exynos4210_mct_init(SysBusDevice
*dev
)
1433 Exynos4210MCTState
*s
= EXYNOS4210_MCT(dev
);
1437 bh
[0] = qemu_bh_new(exynos4210_gfrc_event
, s
);
1438 s
->g_timer
.ptimer_frc
= ptimer_init(bh
[0]);
1439 memset(&s
->g_timer
.reg
, 0, sizeof(struct gregs
));
1442 for (i
= 0; i
< 2; i
++) {
1443 bh
[0] = qemu_bh_new(exynos4210_ltick_event
, &s
->l_timer
[i
]);
1444 bh
[1] = qemu_bh_new(exynos4210_lfrc_event
, &s
->l_timer
[i
]);
1445 s
->l_timer
[i
].tick_timer
.ptimer_tick
= ptimer_init(bh
[0]);
1446 s
->l_timer
[i
].ptimer_frc
= ptimer_init(bh
[1]);
1447 s
->l_timer
[i
].id
= i
;
1451 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
1452 sysbus_init_irq(dev
, &s
->g_timer
.irq
[i
]);
1454 for (i
= 0; i
< 2; i
++) {
1455 sysbus_init_irq(dev
, &s
->l_timer
[i
].irq
);
1458 memory_region_init_io(&s
->iomem
, OBJECT(s
), &exynos4210_mct_ops
, s
,
1459 "exynos4210-mct", MCT_SFR_SIZE
);
1460 sysbus_init_mmio(dev
, &s
->iomem
);
1465 static void exynos4210_mct_class_init(ObjectClass
*klass
, void *data
)
1467 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1468 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
1470 k
->init
= exynos4210_mct_init
;
1471 dc
->reset
= exynos4210_mct_reset
;
1472 dc
->vmsd
= &vmstate_exynos4210_mct_state
;
1475 static const TypeInfo exynos4210_mct_info
= {
1476 .name
= TYPE_EXYNOS4210_MCT
,
1477 .parent
= TYPE_SYS_BUS_DEVICE
,
1478 .instance_size
= sizeof(Exynos4210MCTState
),
1479 .class_init
= exynos4210_mct_class_init
,
1482 static void exynos4210_mct_register_types(void)
1484 type_register_static(&exynos4210_mct_info
);
1487 type_init(exynos4210_mct_register_types
)