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 "qemu/osdep.h"
57 #include "hw/sysbus.h"
58 #include "qemu/timer.h"
59 #include "qemu/main-loop.h"
60 #include "qemu-common.h"
61 #include "hw/ptimer.h"
63 #include "hw/arm/exynos4210.h"
68 #define DPRINTF(fmt, ...) \
69 do { fprintf(stdout, "MCT: [%24s:%5d] " fmt, __func__, __LINE__, \
70 ## __VA_ARGS__); } while (0)
72 #define DPRINTF(fmt, ...) do {} while (0)
78 #define G_CNT_WSTAT 0x110
79 #define G_COMP0_L 0x200
80 #define G_COMP0_U 0x204
81 #define G_COMP0_ADD_INCR 0x208
82 #define G_COMP1_L 0x210
83 #define G_COMP1_U 0x214
84 #define G_COMP1_ADD_INCR 0x218
85 #define G_COMP2_L 0x220
86 #define G_COMP2_U 0x224
87 #define G_COMP2_ADD_INCR 0x228
88 #define G_COMP3_L 0x230
89 #define G_COMP3_U 0x234
90 #define G_COMP3_ADD_INCR 0x238
92 #define G_INT_CSTAT 0x244
93 #define G_INT_ENB 0x248
95 #define L0_TCNTB 0x300
96 #define L0_TCNTO 0x304
97 #define L0_ICNTB 0x308
98 #define L0_ICNTO 0x30C
99 #define L0_FRCNTB 0x310
100 #define L0_FRCNTO 0x314
101 #define L0_TCON 0x320
102 #define L0_INT_CSTAT 0x330
103 #define L0_INT_ENB 0x334
104 #define L0_WSTAT 0x340
105 #define L1_TCNTB 0x400
106 #define L1_TCNTO 0x404
107 #define L1_ICNTB 0x408
108 #define L1_ICNTO 0x40C
109 #define L1_FRCNTB 0x410
110 #define L1_FRCNTO 0x414
111 #define L1_TCON 0x420
112 #define L1_INT_CSTAT 0x430
113 #define L1_INT_ENB 0x434
114 #define L1_WSTAT 0x440
116 #define MCT_CFG_GET_PRESCALER(x) ((x) & 0xFF)
117 #define MCT_CFG_GET_DIVIDER(x) (1 << ((x) >> 8 & 7))
119 #define GET_G_COMP_IDX(offset) (((offset) - G_COMP0_L) / 0x10)
120 #define GET_G_COMP_ADD_INCR_IDX(offset) (((offset) - G_COMP0_ADD_INCR) / 0x10)
122 #define G_COMP_L(x) (G_COMP0_L + (x) * 0x10)
123 #define G_COMP_U(x) (G_COMP0_U + (x) * 0x10)
125 #define G_COMP_ADD_INCR(x) (G_COMP0_ADD_INCR + (x) * 0x10)
128 #define G_TCON_COMP_ENABLE(x) (1 << 2 * (x))
129 #define G_TCON_AUTO_ICREMENT(x) (1 << (2 * (x) + 1))
130 #define G_TCON_TIMER_ENABLE (1 << 8)
132 #define G_INT_ENABLE(x) (1 << (x))
133 #define G_INT_CSTAT_COMP(x) (1 << (x))
135 #define G_CNT_WSTAT_L 1
136 #define G_CNT_WSTAT_U 2
138 #define G_WSTAT_COMP_L(x) (1 << 4 * (x))
139 #define G_WSTAT_COMP_U(x) (1 << ((4 * (x)) + 1))
140 #define G_WSTAT_COMP_ADDINCR(x) (1 << ((4 * (x)) + 2))
141 #define G_WSTAT_TCON_WRITE (1 << 16)
143 #define GET_L_TIMER_IDX(offset) ((((offset) & 0xF00) - L0_TCNTB) / 0x100)
144 #define GET_L_TIMER_CNT_REG_IDX(offset, lt_i) \
145 (((offset) - (L0_TCNTB + 0x100 * (lt_i))) >> 2)
147 #define L_ICNTB_MANUAL_UPDATE (1 << 31)
149 #define L_TCON_TICK_START (1)
150 #define L_TCON_INT_START (1 << 1)
151 #define L_TCON_INTERVAL_MODE (1 << 2)
152 #define L_TCON_FRC_START (1 << 3)
154 #define L_INT_CSTAT_INTCNT (1 << 0)
155 #define L_INT_CSTAT_FRCCNT (1 << 1)
157 #define L_INT_INTENB_ICNTEIE (1 << 0)
158 #define L_INT_INTENB_FRCEIE (1 << 1)
160 #define L_WSTAT_TCNTB_WRITE (1 << 0)
161 #define L_WSTAT_ICNTB_WRITE (1 << 1)
162 #define L_WSTAT_FRCCNTB_WRITE (1 << 2)
163 #define L_WSTAT_TCON_WRITE (1 << 3)
165 enum LocalTimerRegCntIndexes
{
176 #define MCT_SFR_SIZE 0x444
178 #define MCT_GT_CMP_NUM 4
180 #define MCT_GT_COUNTER_STEP 0x100000000ULL
181 #define MCT_LT_COUNTER_STEP 0x100000000ULL
182 #define MCT_LT_CNT_LOW_LIMIT 0x100
186 qemu_irq irq
[MCT_GT_CMP_NUM
];
195 uint64_t comp
[MCT_GT_CMP_NUM
];
196 uint32_t comp_add_incr
[MCT_GT_CMP_NUM
];
199 uint64_t count
; /* Value FRC was armed with */
200 int32_t curr_comp
; /* Current comparator FRC is running to */
202 ptimer_state
*ptimer_frc
; /* FRC timer */
208 int id
; /* timer id */
209 qemu_irq irq
; /* local timer irq */
212 uint32_t cnt_run
; /* cnt timer is running */
213 uint32_t int_run
; /* int timer is running */
217 uint32_t tcntb
; /* initial value for TCNTB */
218 uint32_t icntb
; /* initial value for ICNTB */
221 uint64_t distance
; /* distance to count to the next event */
222 uint64_t progress
; /* progress when counting by steps */
223 uint64_t count
; /* count to arm timer with */
225 ptimer_state
*ptimer_tick
; /* timer for tick counter */
228 /* use ptimer.c to represent count down timer */
230 ptimer_state
*ptimer_frc
; /* timer for free running counter */
234 uint32_t cnt
[L_REG_CNT_AMOUNT
];
243 #define TYPE_EXYNOS4210_MCT "exynos4210.mct"
244 #define EXYNOS4210_MCT(obj) \
245 OBJECT_CHECK(Exynos4210MCTState, (obj), TYPE_EXYNOS4210_MCT)
247 typedef struct Exynos4210MCTState
{
248 SysBusDevice parent_obj
;
253 uint32_t reg_mct_cfg
;
255 Exynos4210MCTLT l_timer
[2];
256 Exynos4210MCTGT g_timer
;
258 uint32_t freq
; /* all timers tick frequency, TCLK */
259 } Exynos4210MCTState
;
262 static const VMStateDescription vmstate_tick_timer
= {
263 .name
= "exynos4210.mct.tick_timer",
265 .minimum_version_id
= 1,
266 .fields
= (VMStateField
[]) {
267 VMSTATE_UINT32(cnt_run
, struct tick_timer
),
268 VMSTATE_UINT32(int_run
, struct tick_timer
),
269 VMSTATE_UINT32(last_icnto
, struct tick_timer
),
270 VMSTATE_UINT32(last_tcnto
, struct tick_timer
),
271 VMSTATE_UINT32(tcntb
, struct tick_timer
),
272 VMSTATE_UINT32(icntb
, struct tick_timer
),
273 VMSTATE_UINT64(distance
, struct tick_timer
),
274 VMSTATE_UINT64(progress
, struct tick_timer
),
275 VMSTATE_UINT64(count
, struct tick_timer
),
276 VMSTATE_PTIMER(ptimer_tick
, struct tick_timer
),
277 VMSTATE_END_OF_LIST()
281 static const VMStateDescription vmstate_lregs
= {
282 .name
= "exynos4210.mct.lregs",
284 .minimum_version_id
= 1,
285 .fields
= (VMStateField
[]) {
286 VMSTATE_UINT32_ARRAY(cnt
, struct lregs
, L_REG_CNT_AMOUNT
),
287 VMSTATE_UINT32(tcon
, struct lregs
),
288 VMSTATE_UINT32(int_cstat
, struct lregs
),
289 VMSTATE_UINT32(int_enb
, struct lregs
),
290 VMSTATE_UINT32(wstat
, struct lregs
),
291 VMSTATE_END_OF_LIST()
295 static const VMStateDescription vmstate_exynos4210_mct_lt
= {
296 .name
= "exynos4210.mct.lt",
298 .minimum_version_id
= 1,
299 .fields
= (VMStateField
[]) {
300 VMSTATE_INT32(id
, Exynos4210MCTLT
),
301 VMSTATE_STRUCT(tick_timer
, Exynos4210MCTLT
, 0,
304 VMSTATE_PTIMER(ptimer_frc
, Exynos4210MCTLT
),
305 VMSTATE_STRUCT(reg
, Exynos4210MCTLT
, 0,
308 VMSTATE_END_OF_LIST()
312 static const VMStateDescription vmstate_gregs
= {
313 .name
= "exynos4210.mct.lregs",
315 .minimum_version_id
= 1,
316 .fields
= (VMStateField
[]) {
317 VMSTATE_UINT64(cnt
, struct gregs
),
318 VMSTATE_UINT32(cnt_wstat
, struct gregs
),
319 VMSTATE_UINT32(tcon
, struct gregs
),
320 VMSTATE_UINT32(int_cstat
, struct gregs
),
321 VMSTATE_UINT32(int_enb
, struct gregs
),
322 VMSTATE_UINT32(wstat
, struct gregs
),
323 VMSTATE_UINT64_ARRAY(comp
, struct gregs
, MCT_GT_CMP_NUM
),
324 VMSTATE_UINT32_ARRAY(comp_add_incr
, struct gregs
,
326 VMSTATE_END_OF_LIST()
330 static const VMStateDescription vmstate_exynos4210_mct_gt
= {
331 .name
= "exynos4210.mct.lt",
333 .minimum_version_id
= 1,
334 .fields
= (VMStateField
[]) {
335 VMSTATE_STRUCT(reg
, Exynos4210MCTGT
, 0, vmstate_gregs
,
337 VMSTATE_UINT64(count
, Exynos4210MCTGT
),
338 VMSTATE_INT32(curr_comp
, Exynos4210MCTGT
),
339 VMSTATE_PTIMER(ptimer_frc
, Exynos4210MCTGT
),
340 VMSTATE_END_OF_LIST()
344 static const VMStateDescription vmstate_exynos4210_mct_state
= {
345 .name
= "exynos4210.mct",
347 .minimum_version_id
= 1,
348 .fields
= (VMStateField
[]) {
349 VMSTATE_UINT32(reg_mct_cfg
, Exynos4210MCTState
),
350 VMSTATE_STRUCT_ARRAY(l_timer
, Exynos4210MCTState
, 2, 0,
351 vmstate_exynos4210_mct_lt
, Exynos4210MCTLT
),
352 VMSTATE_STRUCT(g_timer
, Exynos4210MCTState
, 0,
353 vmstate_exynos4210_mct_gt
, Exynos4210MCTGT
),
354 VMSTATE_UINT32(freq
, Exynos4210MCTState
),
355 VMSTATE_END_OF_LIST()
359 static void exynos4210_mct_update_freq(Exynos4210MCTState
*s
);
362 * Set counter of FRC global timer.
364 static void exynos4210_gfrc_set_count(Exynos4210MCTGT
*s
, uint64_t count
)
367 DPRINTF("global timer frc set count 0x%llx\n", count
);
368 ptimer_set_count(s
->ptimer_frc
, count
);
372 * Get counter of FRC global timer.
374 static uint64_t exynos4210_gfrc_get_count(Exynos4210MCTGT
*s
)
377 count
= ptimer_get_count(s
->ptimer_frc
);
378 count
= s
->count
- count
;
379 return s
->reg
.cnt
+ count
;
383 * Stop global FRC timer
385 static void exynos4210_gfrc_stop(Exynos4210MCTGT
*s
)
387 DPRINTF("global timer frc stop\n");
389 ptimer_stop(s
->ptimer_frc
);
393 * Start global FRC timer
395 static void exynos4210_gfrc_start(Exynos4210MCTGT
*s
)
397 DPRINTF("global timer frc start\n");
399 ptimer_run(s
->ptimer_frc
, 1);
403 * Find next nearest Comparator. If current Comparator value equals to other
404 * Comparator value, skip them both
406 static int32_t exynos4210_gcomp_find(Exynos4210MCTState
*s
)
415 uint64_t distance_min
;
419 gfrc
= exynos4210_gfrc_get_count(&s
->g_timer
);
422 distance_min
= UINT64_MAX
;
423 comp_i
= MCT_GT_CMP_NUM
;
424 min_comp_i
= MCT_GT_CMP_NUM
;
427 /* lookup for nearest comparator */
428 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
430 if (s
->g_timer
.reg
.tcon
& G_TCON_COMP_ENABLE(i
)) {
434 if (s
->g_timer
.reg
.comp
[i
] > gfrc
) {
435 /* Comparator is upper then FRC */
436 distance
= s
->g_timer
.reg
.comp
[i
] - gfrc
;
438 if (distance
<= distance_min
) {
439 distance_min
= distance
;
443 /* Comparator is below FRC, find the smallest */
445 if (s
->g_timer
.reg
.comp
[i
] <= min
) {
446 min
= s
->g_timer
.reg
.comp
[i
];
454 /* All Comparators disabled */
456 } else if (comp_i
< MCT_GT_CMP_NUM
) {
457 /* Found upper Comparator */
460 /* All Comparators are below or equal to FRC */
464 DPRINTF("found comparator %d: comp 0x%llx distance 0x%llx, gfrc 0x%llx\n",
466 s
->g_timer
.reg
.comp
[res
],
474 * Get distance to nearest Comparator
476 static uint64_t exynos4210_gcomp_get_distance(Exynos4210MCTState
*s
, int32_t id
)
479 /* no enabled Comparators, choose max distance */
480 return MCT_GT_COUNTER_STEP
;
482 if (s
->g_timer
.reg
.comp
[id
] - s
->g_timer
.reg
.cnt
< MCT_GT_COUNTER_STEP
) {
483 return s
->g_timer
.reg
.comp
[id
] - s
->g_timer
.reg
.cnt
;
485 return MCT_GT_COUNTER_STEP
;
490 * Restart global FRC timer
492 static void exynos4210_gfrc_restart(Exynos4210MCTState
*s
)
496 exynos4210_gfrc_stop(&s
->g_timer
);
498 s
->g_timer
.curr_comp
= exynos4210_gcomp_find(s
);
500 distance
= exynos4210_gcomp_get_distance(s
, s
->g_timer
.curr_comp
);
502 if (distance
> MCT_GT_COUNTER_STEP
|| !distance
) {
503 distance
= MCT_GT_COUNTER_STEP
;
506 exynos4210_gfrc_set_count(&s
->g_timer
, distance
);
507 exynos4210_gfrc_start(&s
->g_timer
);
511 * Raise global timer CMP IRQ
513 static void exynos4210_gcomp_raise_irq(void *opaque
, uint32_t id
)
515 Exynos4210MCTGT
*s
= opaque
;
517 /* If CSTAT is pending and IRQ is enabled */
518 if ((s
->reg
.int_cstat
& G_INT_CSTAT_COMP(id
)) &&
519 (s
->reg
.int_enb
& G_INT_ENABLE(id
))) {
520 DPRINTF("gcmp timer[%d] IRQ\n", id
);
521 qemu_irq_raise(s
->irq
[id
]);
526 * Lower global timer CMP IRQ
528 static void exynos4210_gcomp_lower_irq(void *opaque
, uint32_t id
)
530 Exynos4210MCTGT
*s
= opaque
;
531 qemu_irq_lower(s
->irq
[id
]);
535 * Global timer FRC event handler.
536 * Each event occurs when internal counter reaches counter + MCT_GT_COUNTER_STEP
537 * Every time we arm global FRC timer to count for MCT_GT_COUNTER_STEP value
539 static void exynos4210_gfrc_event(void *opaque
)
541 Exynos4210MCTState
*s
= (Exynos4210MCTState
*)opaque
;
547 s
->g_timer
.reg
.cnt
+= s
->g_timer
.count
;
549 /* Process all comparators */
550 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
552 if (s
->g_timer
.reg
.cnt
== s
->g_timer
.reg
.comp
[i
]) {
553 /* reached nearest comparator */
555 s
->g_timer
.reg
.int_cstat
|= G_INT_CSTAT_COMP(i
);
558 if (s
->g_timer
.reg
.tcon
& G_TCON_AUTO_ICREMENT(i
)) {
559 s
->g_timer
.reg
.comp
[i
] += s
->g_timer
.reg
.comp_add_incr
[i
];
563 exynos4210_gcomp_raise_irq(&s
->g_timer
, i
);
567 /* Reload FRC to reach nearest comparator */
568 s
->g_timer
.curr_comp
= exynos4210_gcomp_find(s
);
569 distance
= exynos4210_gcomp_get_distance(s
, s
->g_timer
.curr_comp
);
570 if (distance
> MCT_GT_COUNTER_STEP
|| !distance
) {
571 distance
= MCT_GT_COUNTER_STEP
;
573 exynos4210_gfrc_set_count(&s
->g_timer
, distance
);
575 exynos4210_gfrc_start(&s
->g_timer
);
579 * Get counter of FRC local timer.
581 static uint64_t exynos4210_lfrc_get_count(Exynos4210MCTLT
*s
)
583 return ptimer_get_count(s
->ptimer_frc
);
587 * Set counter of FRC local timer.
589 static void exynos4210_lfrc_update_count(Exynos4210MCTLT
*s
)
591 if (!s
->reg
.cnt
[L_REG_CNT_FRCCNTB
]) {
592 ptimer_set_count(s
->ptimer_frc
, MCT_LT_COUNTER_STEP
);
594 ptimer_set_count(s
->ptimer_frc
, s
->reg
.cnt
[L_REG_CNT_FRCCNTB
]);
599 * Start local FRC timer
601 static void exynos4210_lfrc_start(Exynos4210MCTLT
*s
)
603 ptimer_run(s
->ptimer_frc
, 1);
607 * Stop local FRC timer
609 static void exynos4210_lfrc_stop(Exynos4210MCTLT
*s
)
611 ptimer_stop(s
->ptimer_frc
);
615 * Local timer free running counter tick handler
617 static void exynos4210_lfrc_event(void *opaque
)
619 Exynos4210MCTLT
* s
= (Exynos4210MCTLT
*)opaque
;
621 /* local frc expired */
625 s
->reg
.int_cstat
|= L_INT_CSTAT_FRCCNT
;
627 /* update frc counter */
628 exynos4210_lfrc_update_count(s
);
631 if (s
->reg
.int_enb
& L_INT_INTENB_FRCEIE
) {
632 qemu_irq_raise(s
->irq
);
635 /* we reached here, this means that timer is enabled */
636 exynos4210_lfrc_start(s
);
639 static uint32_t exynos4210_ltick_int_get_cnto(struct tick_timer
*s
);
640 static uint32_t exynos4210_ltick_cnt_get_cnto(struct tick_timer
*s
);
641 static void exynos4210_ltick_recalc_count(struct tick_timer
*s
);
644 * Action on enabling local tick int timer
646 static void exynos4210_ltick_int_start(struct tick_timer
*s
)
654 * Action on disabling local tick int timer
656 static void exynos4210_ltick_int_stop(struct tick_timer
*s
)
659 s
->last_icnto
= exynos4210_ltick_int_get_cnto(s
);
665 * Get count for INT timer
667 static uint32_t exynos4210_ltick_int_get_cnto(struct tick_timer
*s
)
673 uint64_t cur_progress
;
675 count
= ptimer_get_count(s
->ptimer_tick
);
677 /* timer is still counting, called not from event */
678 counted
= s
->count
- ptimer_get_count(s
->ptimer_tick
);
679 cur_progress
= s
->progress
+ counted
;
681 /* timer expired earlier */
682 cur_progress
= s
->progress
;
685 remain
= s
->distance
- cur_progress
;
688 /* INT is stopped. */
689 icnto
= s
->last_icnto
;
691 /* Both are counting */
692 icnto
= remain
/ s
->tcntb
;
699 * Start local tick cnt timer.
701 static void exynos4210_ltick_cnt_start(struct tick_timer
*s
)
705 exynos4210_ltick_recalc_count(s
);
706 ptimer_set_count(s
->ptimer_tick
, s
->count
);
707 ptimer_run(s
->ptimer_tick
, 1);
714 * Stop local tick cnt timer.
716 static void exynos4210_ltick_cnt_stop(struct tick_timer
*s
)
720 s
->last_tcnto
= exynos4210_ltick_cnt_get_cnto(s
);
723 exynos4210_ltick_int_stop(s
);
726 ptimer_stop(s
->ptimer_tick
);
733 * Get counter for CNT timer
735 static uint32_t exynos4210_ltick_cnt_get_cnto(struct tick_timer
*s
)
742 uint64_t cur_progress
;
744 count
= ptimer_get_count(s
->ptimer_tick
);
746 /* timer is still counting, called not from event */
747 counted
= s
->count
- ptimer_get_count(s
->ptimer_tick
);
748 cur_progress
= s
->progress
+ counted
;
750 /* timer expired earlier */
751 cur_progress
= s
->progress
;
754 remain
= s
->distance
- cur_progress
;
757 /* Both are stopped. */
758 tcnto
= s
->last_tcnto
;
759 } else if (!s
->int_run
) {
760 /* INT counter is stopped, progress is by CNT timer */
761 tcnto
= remain
% s
->tcntb
;
763 /* Both are counting */
764 icnto
= remain
/ s
->tcntb
;
766 tcnto
= remain
% (icnto
* s
->tcntb
);
768 tcnto
= remain
% s
->tcntb
;
776 * Set new values of counters for CNT and INT timers
778 static void exynos4210_ltick_set_cntb(struct tick_timer
*s
, uint32_t new_cnt
,
781 uint32_t cnt_stopped
= 0;
782 uint32_t int_stopped
= 0;
785 exynos4210_ltick_cnt_stop(s
);
790 exynos4210_ltick_int_stop(s
);
794 s
->tcntb
= new_cnt
+ 1;
795 s
->icntb
= new_int
+ 1;
798 exynos4210_ltick_cnt_start(s
);
801 exynos4210_ltick_int_start(s
);
807 * Calculate new counter value for tick timer
809 static void exynos4210_ltick_recalc_count(struct tick_timer
*s
)
813 if ((s
->cnt_run
&& s
->last_tcnto
) || (s
->int_run
&& s
->last_icnto
)) {
815 * one or both timers run and not counted to the end;
816 * distance is not passed, recalculate with last_tcnto * last_icnto
820 to_count
= (uint64_t)s
->last_tcnto
* s
->last_icnto
;
822 to_count
= s
->last_icnto
;
825 /* distance is passed, recalculate with tcnto * icnto */
827 s
->distance
= (uint64_t)s
->tcntb
* s
->icntb
;
829 s
->distance
= s
->tcntb
;
832 to_count
= s
->distance
;
836 if (to_count
> MCT_LT_COUNTER_STEP
) {
838 s
->count
= MCT_LT_COUNTER_STEP
;
845 * Initialize tick_timer
847 static void exynos4210_ltick_timer_init(struct tick_timer
*s
)
849 exynos4210_ltick_int_stop(s
);
850 exynos4210_ltick_cnt_stop(s
);
861 * Raises when abstract tick_timer expires.
863 static void exynos4210_ltick_timer_event(struct tick_timer
*s
)
865 s
->progress
+= s
->count
;
869 * Local timer tick counter handler.
870 * Don't use reloaded timers. If timer counter = zero
871 * then handler called but after handler finished no
872 * timer reload occurs.
874 static void exynos4210_ltick_event(void *opaque
)
876 Exynos4210MCTLT
* s
= (Exynos4210MCTLT
*)opaque
;
880 static uint64_t time1
[2] = {0};
881 static uint64_t time2
[2] = {0};
884 /* Call tick_timer event handler, it will update its tcntb and icntb. */
885 exynos4210_ltick_timer_event(&s
->tick_timer
);
887 /* get tick_timer cnt */
888 tcnto
= exynos4210_ltick_cnt_get_cnto(&s
->tick_timer
);
890 /* get tick_timer int */
891 icnto
= exynos4210_ltick_int_get_cnto(&s
->tick_timer
);
893 /* raise IRQ if needed */
894 if (!icnto
&& s
->reg
.tcon
& L_TCON_INT_START
) {
895 /* INT counter enabled and expired */
897 s
->reg
.int_cstat
|= L_INT_CSTAT_INTCNT
;
899 /* raise interrupt if enabled */
900 if (s
->reg
.int_enb
& L_INT_INTENB_ICNTEIE
) {
902 time2
[s
->id
] = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
903 DPRINTF("local timer[%d] IRQ: %llx\n", s
->id
,
904 time2
[s
->id
] - time1
[s
->id
]);
905 time1
[s
->id
] = time2
[s
->id
];
907 qemu_irq_raise(s
->irq
);
911 if (s
->reg
.tcon
& L_TCON_INTERVAL_MODE
) {
912 exynos4210_ltick_set_cntb(&s
->tick_timer
,
913 s
->reg
.cnt
[L_REG_CNT_TCNTB
],
914 s
->reg
.cnt
[L_REG_CNT_ICNTB
]);
919 exynos4210_ltick_set_cntb(&s
->tick_timer
,
920 s
->reg
.cnt
[L_REG_CNT_TCNTB
],
925 /* start tick_timer cnt */
926 exynos4210_ltick_cnt_start(&s
->tick_timer
);
928 /* start tick_timer int */
929 exynos4210_ltick_int_start(&s
->tick_timer
);
932 /* update timer frequency */
933 static void exynos4210_mct_update_freq(Exynos4210MCTState
*s
)
935 uint32_t freq
= s
->freq
;
937 ((MCT_CFG_GET_PRESCALER(s
->reg_mct_cfg
) + 1) *
938 MCT_CFG_GET_DIVIDER(s
->reg_mct_cfg
));
940 if (freq
!= s
->freq
) {
941 DPRINTF("freq=%dHz\n", s
->freq
);
944 ptimer_set_freq(s
->g_timer
.ptimer_frc
, s
->freq
);
947 ptimer_set_freq(s
->l_timer
[0].tick_timer
.ptimer_tick
, s
->freq
);
948 ptimer_set_freq(s
->l_timer
[0].ptimer_frc
, s
->freq
);
949 ptimer_set_freq(s
->l_timer
[1].tick_timer
.ptimer_tick
, s
->freq
);
950 ptimer_set_freq(s
->l_timer
[1].ptimer_frc
, s
->freq
);
954 /* set defaul_timer values for all fields */
955 static void exynos4210_mct_reset(DeviceState
*d
)
957 Exynos4210MCTState
*s
= EXYNOS4210_MCT(d
);
963 memset(&s
->g_timer
.reg
, 0, sizeof(s
->g_timer
.reg
));
964 exynos4210_gfrc_stop(&s
->g_timer
);
967 memset(s
->l_timer
[0].reg
.cnt
, 0, sizeof(s
->l_timer
[0].reg
.cnt
));
968 memset(s
->l_timer
[1].reg
.cnt
, 0, sizeof(s
->l_timer
[1].reg
.cnt
));
969 for (i
= 0; i
< 2; i
++) {
970 s
->l_timer
[i
].reg
.int_cstat
= 0;
971 s
->l_timer
[i
].reg
.int_enb
= 0;
972 s
->l_timer
[i
].reg
.tcon
= 0;
973 s
->l_timer
[i
].reg
.wstat
= 0;
974 s
->l_timer
[i
].tick_timer
.count
= 0;
975 s
->l_timer
[i
].tick_timer
.distance
= 0;
976 s
->l_timer
[i
].tick_timer
.progress
= 0;
977 ptimer_stop(s
->l_timer
[i
].ptimer_frc
);
979 exynos4210_ltick_timer_init(&s
->l_timer
[i
].tick_timer
);
982 exynos4210_mct_update_freq(s
);
986 /* Multi Core Timer read */
987 static uint64_t exynos4210_mct_read(void *opaque
, hwaddr offset
,
990 Exynos4210MCTState
*s
= (Exynos4210MCTState
*)opaque
;
1000 value
= s
->reg_mct_cfg
;
1003 case G_CNT_L
: case G_CNT_U
:
1004 shift
= 8 * (offset
& 0x4);
1005 count
= exynos4210_gfrc_get_count(&s
->g_timer
);
1006 value
= UINT32_MAX
& (count
>> shift
);
1007 DPRINTF("read FRC=0x%llx\n", count
);
1011 value
= s
->g_timer
.reg
.cnt_wstat
;
1014 case G_COMP_L(0): case G_COMP_L(1): case G_COMP_L(2): case G_COMP_L(3):
1015 case G_COMP_U(0): case G_COMP_U(1): case G_COMP_U(2): case G_COMP_U(3):
1016 index
= GET_G_COMP_IDX(offset
);
1017 shift
= 8 * (offset
& 0x4);
1018 value
= UINT32_MAX
& (s
->g_timer
.reg
.comp
[index
] >> shift
);
1022 value
= s
->g_timer
.reg
.tcon
;
1026 value
= s
->g_timer
.reg
.int_cstat
;
1030 value
= s
->g_timer
.reg
.int_enb
;
1033 value
= s
->g_timer
.reg
.wstat
;
1036 case G_COMP0_ADD_INCR
: case G_COMP1_ADD_INCR
:
1037 case G_COMP2_ADD_INCR
: case G_COMP3_ADD_INCR
:
1038 value
= s
->g_timer
.reg
.comp_add_incr
[GET_G_COMP_ADD_INCR_IDX(offset
)];
1042 case L0_TCNTB
: case L0_ICNTB
: case L0_FRCNTB
:
1043 case L1_TCNTB
: case L1_ICNTB
: case L1_FRCNTB
:
1044 lt_i
= GET_L_TIMER_IDX(offset
);
1045 index
= GET_L_TIMER_CNT_REG_IDX(offset
, lt_i
);
1046 value
= s
->l_timer
[lt_i
].reg
.cnt
[index
];
1049 case L0_TCNTO
: case L1_TCNTO
:
1050 lt_i
= GET_L_TIMER_IDX(offset
);
1052 value
= exynos4210_ltick_cnt_get_cnto(&s
->l_timer
[lt_i
].tick_timer
);
1053 DPRINTF("local timer[%d] read TCNTO %x\n", lt_i
, value
);
1056 case L0_ICNTO
: case L1_ICNTO
:
1057 lt_i
= GET_L_TIMER_IDX(offset
);
1059 value
= exynos4210_ltick_int_get_cnto(&s
->l_timer
[lt_i
].tick_timer
);
1060 DPRINTF("local timer[%d] read ICNTO %x\n", lt_i
, value
);
1063 case L0_FRCNTO
: case L1_FRCNTO
:
1064 lt_i
= GET_L_TIMER_IDX(offset
);
1066 value
= exynos4210_lfrc_get_count(&s
->l_timer
[lt_i
]);
1069 case L0_TCON
: case L1_TCON
:
1070 lt_i
= ((offset
& 0xF00) - L0_TCNTB
) / 0x100;
1071 value
= s
->l_timer
[lt_i
].reg
.tcon
;
1074 case L0_INT_CSTAT
: case L1_INT_CSTAT
:
1075 lt_i
= ((offset
& 0xF00) - L0_TCNTB
) / 0x100;
1076 value
= s
->l_timer
[lt_i
].reg
.int_cstat
;
1079 case L0_INT_ENB
: case L1_INT_ENB
:
1080 lt_i
= ((offset
& 0xF00) - L0_TCNTB
) / 0x100;
1081 value
= s
->l_timer
[lt_i
].reg
.int_enb
;
1084 case L0_WSTAT
: case L1_WSTAT
:
1085 lt_i
= ((offset
& 0xF00) - L0_TCNTB
) / 0x100;
1086 value
= s
->l_timer
[lt_i
].reg
.wstat
;
1090 hw_error("exynos4210.mct: bad read offset "
1091 TARGET_FMT_plx
"\n", offset
);
1098 static void exynos4210_mct_write(void *opaque
, hwaddr offset
,
1099 uint64_t value
, unsigned size
)
1101 Exynos4210MCTState
*s
= (Exynos4210MCTState
*)opaque
;
1102 int index
; /* index in buffer which represents register set */
1109 static uint32_t icntb_max
[2] = {0};
1110 static uint32_t icntb_min
[2] = {UINT32_MAX
, UINT32_MAX
};
1111 static uint32_t tcntb_max
[2] = {0};
1112 static uint32_t tcntb_min
[2] = {UINT32_MAX
, UINT32_MAX
};
1115 new_frc
= s
->g_timer
.reg
.cnt
;
1120 s
->reg_mct_cfg
= value
;
1121 exynos4210_mct_update_freq(s
);
1126 if (offset
== G_CNT_L
) {
1128 DPRINTF("global timer write to reg.cntl %llx\n", value
);
1130 new_frc
= (s
->g_timer
.reg
.cnt
& (uint64_t)UINT32_MAX
<< 32) + value
;
1131 s
->g_timer
.reg
.cnt_wstat
|= G_CNT_WSTAT_L
;
1133 if (offset
== G_CNT_U
) {
1135 DPRINTF("global timer write to reg.cntu %llx\n", value
);
1137 new_frc
= (s
->g_timer
.reg
.cnt
& UINT32_MAX
) +
1138 ((uint64_t)value
<< 32);
1139 s
->g_timer
.reg
.cnt_wstat
|= G_CNT_WSTAT_U
;
1142 s
->g_timer
.reg
.cnt
= new_frc
;
1143 exynos4210_gfrc_restart(s
);
1147 s
->g_timer
.reg
.cnt_wstat
&= ~(value
);
1150 case G_COMP_L(0): case G_COMP_L(1): case G_COMP_L(2): case G_COMP_L(3):
1151 case G_COMP_U(0): case G_COMP_U(1): case G_COMP_U(2): case G_COMP_U(3):
1152 index
= GET_G_COMP_IDX(offset
);
1153 shift
= 8 * (offset
& 0x4);
1154 s
->g_timer
.reg
.comp
[index
] =
1155 (s
->g_timer
.reg
.comp
[index
] &
1156 (((uint64_t)UINT32_MAX
<< 32) >> shift
)) +
1159 DPRINTF("comparator %d write 0x%llx val << %d\n", index
, value
, shift
);
1162 s
->g_timer
.reg
.wstat
|= G_WSTAT_COMP_U(index
);
1164 s
->g_timer
.reg
.wstat
|= G_WSTAT_COMP_L(index
);
1167 exynos4210_gfrc_restart(s
);
1171 old_val
= s
->g_timer
.reg
.tcon
;
1172 s
->g_timer
.reg
.tcon
= value
;
1173 s
->g_timer
.reg
.wstat
|= G_WSTAT_TCON_WRITE
;
1175 DPRINTF("global timer write to reg.g_tcon %llx\n", value
);
1177 /* Start FRC if transition from disabled to enabled */
1178 if ((value
& G_TCON_TIMER_ENABLE
) > (old_val
&
1179 G_TCON_TIMER_ENABLE
)) {
1180 exynos4210_gfrc_start(&s
->g_timer
);
1182 if ((value
& G_TCON_TIMER_ENABLE
) < (old_val
&
1183 G_TCON_TIMER_ENABLE
)) {
1184 exynos4210_gfrc_stop(&s
->g_timer
);
1187 /* Start CMP if transition from disabled to enabled */
1188 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
1189 if ((value
& G_TCON_COMP_ENABLE(i
)) != (old_val
&
1190 G_TCON_COMP_ENABLE(i
))) {
1191 exynos4210_gfrc_restart(s
);
1197 s
->g_timer
.reg
.int_cstat
&= ~(value
);
1198 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
1199 if (value
& G_INT_CSTAT_COMP(i
)) {
1200 exynos4210_gcomp_lower_irq(&s
->g_timer
, i
);
1206 /* Raise IRQ if transition from disabled to enabled and CSTAT pending */
1207 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
1208 if ((value
& G_INT_ENABLE(i
)) > (s
->g_timer
.reg
.tcon
&
1210 if (s
->g_timer
.reg
.int_cstat
& G_INT_CSTAT_COMP(i
)) {
1211 exynos4210_gcomp_raise_irq(&s
->g_timer
, i
);
1215 if ((value
& G_INT_ENABLE(i
)) < (s
->g_timer
.reg
.tcon
&
1217 exynos4210_gcomp_lower_irq(&s
->g_timer
, i
);
1221 DPRINTF("global timer INT enable %llx\n", value
);
1222 s
->g_timer
.reg
.int_enb
= value
;
1226 s
->g_timer
.reg
.wstat
&= ~(value
);
1229 case G_COMP0_ADD_INCR
: case G_COMP1_ADD_INCR
:
1230 case G_COMP2_ADD_INCR
: case G_COMP3_ADD_INCR
:
1231 index
= GET_G_COMP_ADD_INCR_IDX(offset
);
1232 s
->g_timer
.reg
.comp_add_incr
[index
] = value
;
1233 s
->g_timer
.reg
.wstat
|= G_WSTAT_COMP_ADDINCR(index
);
1237 case L0_TCON
: case L1_TCON
:
1238 lt_i
= GET_L_TIMER_IDX(offset
);
1239 old_val
= s
->l_timer
[lt_i
].reg
.tcon
;
1241 s
->l_timer
[lt_i
].reg
.wstat
|= L_WSTAT_TCON_WRITE
;
1242 s
->l_timer
[lt_i
].reg
.tcon
= value
;
1244 /* Stop local CNT */
1245 if ((value
& L_TCON_TICK_START
) <
1246 (old_val
& L_TCON_TICK_START
)) {
1247 DPRINTF("local timer[%d] stop cnt\n", lt_i
);
1248 exynos4210_ltick_cnt_stop(&s
->l_timer
[lt_i
].tick_timer
);
1251 /* Stop local INT */
1252 if ((value
& L_TCON_INT_START
) <
1253 (old_val
& L_TCON_INT_START
)) {
1254 DPRINTF("local timer[%d] stop int\n", lt_i
);
1255 exynos4210_ltick_int_stop(&s
->l_timer
[lt_i
].tick_timer
);
1258 /* Start local CNT */
1259 if ((value
& L_TCON_TICK_START
) >
1260 (old_val
& L_TCON_TICK_START
)) {
1261 DPRINTF("local timer[%d] start cnt\n", lt_i
);
1262 exynos4210_ltick_cnt_start(&s
->l_timer
[lt_i
].tick_timer
);
1265 /* Start local INT */
1266 if ((value
& L_TCON_INT_START
) >
1267 (old_val
& L_TCON_INT_START
)) {
1268 DPRINTF("local timer[%d] start int\n", lt_i
);
1269 exynos4210_ltick_int_start(&s
->l_timer
[lt_i
].tick_timer
);
1272 /* Start or Stop local FRC if TCON changed */
1273 if ((value
& L_TCON_FRC_START
) >
1274 (s
->l_timer
[lt_i
].reg
.tcon
& L_TCON_FRC_START
)) {
1275 DPRINTF("local timer[%d] start frc\n", lt_i
);
1276 exynos4210_lfrc_start(&s
->l_timer
[lt_i
]);
1278 if ((value
& L_TCON_FRC_START
) <
1279 (s
->l_timer
[lt_i
].reg
.tcon
& L_TCON_FRC_START
)) {
1280 DPRINTF("local timer[%d] stop frc\n", lt_i
);
1281 exynos4210_lfrc_stop(&s
->l_timer
[lt_i
]);
1285 case L0_TCNTB
: case L1_TCNTB
:
1286 lt_i
= GET_L_TIMER_IDX(offset
);
1287 index
= GET_L_TIMER_CNT_REG_IDX(offset
, lt_i
);
1290 * TCNTB is updated to internal register only after CNT expired.
1291 * Due to this we should reload timer to nearest moment when CNT is
1292 * expired and then in event handler update tcntb to new TCNTB value.
1294 exynos4210_ltick_set_cntb(&s
->l_timer
[lt_i
].tick_timer
, value
,
1295 s
->l_timer
[lt_i
].tick_timer
.icntb
);
1297 s
->l_timer
[lt_i
].reg
.wstat
|= L_WSTAT_TCNTB_WRITE
;
1298 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_TCNTB
] = value
;
1301 if (tcntb_min
[lt_i
] > value
) {
1302 tcntb_min
[lt_i
] = value
;
1304 if (tcntb_max
[lt_i
] < value
) {
1305 tcntb_max
[lt_i
] = value
;
1307 DPRINTF("local timer[%d] TCNTB write %llx; max=%x, min=%x\n",
1308 lt_i
, value
, tcntb_max
[lt_i
], tcntb_min
[lt_i
]);
1312 case L0_ICNTB
: case L1_ICNTB
:
1313 lt_i
= GET_L_TIMER_IDX(offset
);
1314 index
= GET_L_TIMER_CNT_REG_IDX(offset
, lt_i
);
1316 s
->l_timer
[lt_i
].reg
.wstat
|= L_WSTAT_ICNTB_WRITE
;
1317 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_ICNTB
] = value
&
1318 ~L_ICNTB_MANUAL_UPDATE
;
1321 * We need to avoid too small values for TCNTB*ICNTB. If not, IRQ event
1322 * could raise too fast disallowing QEMU to execute target code.
1324 if (s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_ICNTB
] *
1325 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_TCNTB
] < MCT_LT_CNT_LOW_LIMIT
) {
1326 if (!s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_TCNTB
]) {
1327 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_ICNTB
] =
1328 MCT_LT_CNT_LOW_LIMIT
;
1330 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_ICNTB
] =
1331 MCT_LT_CNT_LOW_LIMIT
/
1332 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_TCNTB
];
1336 if (value
& L_ICNTB_MANUAL_UPDATE
) {
1337 exynos4210_ltick_set_cntb(&s
->l_timer
[lt_i
].tick_timer
,
1338 s
->l_timer
[lt_i
].tick_timer
.tcntb
,
1339 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_ICNTB
]);
1343 if (icntb_min
[lt_i
] > value
) {
1344 icntb_min
[lt_i
] = value
;
1346 if (icntb_max
[lt_i
] < value
) {
1347 icntb_max
[lt_i
] = value
;
1349 DPRINTF("local timer[%d] ICNTB write %llx; max=%x, min=%x\n\n",
1350 lt_i
, value
, icntb_max
[lt_i
], icntb_min
[lt_i
]);
1354 case L0_FRCNTB
: case L1_FRCNTB
:
1355 lt_i
= GET_L_TIMER_IDX(offset
);
1356 index
= GET_L_TIMER_CNT_REG_IDX(offset
, lt_i
);
1358 DPRINTF("local timer[%d] FRCNTB write %llx\n", lt_i
, value
);
1360 s
->l_timer
[lt_i
].reg
.wstat
|= L_WSTAT_FRCCNTB_WRITE
;
1361 s
->l_timer
[lt_i
].reg
.cnt
[L_REG_CNT_FRCCNTB
] = value
;
1365 case L0_TCNTO
: case L1_TCNTO
:
1366 case L0_ICNTO
: case L1_ICNTO
:
1367 case L0_FRCNTO
: case L1_FRCNTO
:
1368 qemu_log_mask(LOG_GUEST_ERROR
,
1369 "exynos4210.mct: write to RO register " TARGET_FMT_plx
,
1373 case L0_INT_CSTAT
: case L1_INT_CSTAT
:
1374 lt_i
= GET_L_TIMER_IDX(offset
);
1376 DPRINTF("local timer[%d] CSTAT write %llx\n", lt_i
, value
);
1378 s
->l_timer
[lt_i
].reg
.int_cstat
&= ~value
;
1379 if (!s
->l_timer
[lt_i
].reg
.int_cstat
) {
1380 qemu_irq_lower(s
->l_timer
[lt_i
].irq
);
1384 case L0_INT_ENB
: case L1_INT_ENB
:
1385 lt_i
= GET_L_TIMER_IDX(offset
);
1386 old_val
= s
->l_timer
[lt_i
].reg
.int_enb
;
1388 /* Raise Local timer IRQ if cstat is pending */
1389 if ((value
& L_INT_INTENB_ICNTEIE
) > (old_val
& L_INT_INTENB_ICNTEIE
)) {
1390 if (s
->l_timer
[lt_i
].reg
.int_cstat
& L_INT_CSTAT_INTCNT
) {
1391 qemu_irq_raise(s
->l_timer
[lt_i
].irq
);
1395 s
->l_timer
[lt_i
].reg
.int_enb
= value
;
1399 case L0_WSTAT
: case L1_WSTAT
:
1400 lt_i
= GET_L_TIMER_IDX(offset
);
1402 s
->l_timer
[lt_i
].reg
.wstat
&= ~value
;
1406 hw_error("exynos4210.mct: bad write offset "
1407 TARGET_FMT_plx
"\n", offset
);
1412 static const MemoryRegionOps exynos4210_mct_ops
= {
1413 .read
= exynos4210_mct_read
,
1414 .write
= exynos4210_mct_write
,
1415 .endianness
= DEVICE_NATIVE_ENDIAN
,
1419 static void exynos4210_mct_init(Object
*obj
)
1422 Exynos4210MCTState
*s
= EXYNOS4210_MCT(obj
);
1423 SysBusDevice
*dev
= SYS_BUS_DEVICE(obj
);
1427 bh
[0] = qemu_bh_new(exynos4210_gfrc_event
, s
);
1428 s
->g_timer
.ptimer_frc
= ptimer_init(bh
[0], PTIMER_POLICY_DEFAULT
);
1429 memset(&s
->g_timer
.reg
, 0, sizeof(struct gregs
));
1432 for (i
= 0; i
< 2; i
++) {
1433 bh
[0] = qemu_bh_new(exynos4210_ltick_event
, &s
->l_timer
[i
]);
1434 bh
[1] = qemu_bh_new(exynos4210_lfrc_event
, &s
->l_timer
[i
]);
1435 s
->l_timer
[i
].tick_timer
.ptimer_tick
=
1436 ptimer_init(bh
[0], PTIMER_POLICY_DEFAULT
);
1437 s
->l_timer
[i
].ptimer_frc
= ptimer_init(bh
[1], PTIMER_POLICY_DEFAULT
);
1438 s
->l_timer
[i
].id
= i
;
1442 for (i
= 0; i
< MCT_GT_CMP_NUM
; i
++) {
1443 sysbus_init_irq(dev
, &s
->g_timer
.irq
[i
]);
1445 for (i
= 0; i
< 2; i
++) {
1446 sysbus_init_irq(dev
, &s
->l_timer
[i
].irq
);
1449 memory_region_init_io(&s
->iomem
, obj
, &exynos4210_mct_ops
, s
,
1450 "exynos4210-mct", MCT_SFR_SIZE
);
1451 sysbus_init_mmio(dev
, &s
->iomem
);
1454 static void exynos4210_mct_class_init(ObjectClass
*klass
, void *data
)
1456 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1458 dc
->reset
= exynos4210_mct_reset
;
1459 dc
->vmsd
= &vmstate_exynos4210_mct_state
;
1462 static const TypeInfo exynos4210_mct_info
= {
1463 .name
= TYPE_EXYNOS4210_MCT
,
1464 .parent
= TYPE_SYS_BUS_DEVICE
,
1465 .instance_size
= sizeof(Exynos4210MCTState
),
1466 .instance_init
= exynos4210_mct_init
,
1467 .class_init
= exynos4210_mct_class_init
,
1470 static void exynos4210_mct_register_types(void)
1472 type_register_static(&exynos4210_mct_info
);
1475 type_init(exynos4210_mct_register_types
)