xref: /openbmc/qemu/hw/timer/aspeed_timer.c (revision 72d96f8e2288e4bc7b31011c0c3f00448e2cef19)
1 /*
2  * ASPEED AST2400 Timer
3  *
4  * Andrew Jeffery <andrew@aj.id.au>
5  *
6  * Copyright (C) 2016 IBM Corp.
7  *
8  * This code is licensed under the GPL version 2 or later.  See
9  * the COPYING file in the top-level directory.
10  */
11 
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "hw/irq.h"
15 #include "hw/sysbus.h"
16 #include "hw/timer/aspeed_timer.h"
17 #include "migration/vmstate.h"
18 #include "qemu/bitops.h"
19 #include "qemu/timer.h"
20 #include "qemu/log.h"
21 #include "qemu/module.h"
22 #include "trace.h"
23 
24 #define TIMER_NR_REGS 4
25 
26 #define TIMER_CTRL_BITS 4
27 #define TIMER_CTRL_MASK ((1 << TIMER_CTRL_BITS) - 1)
28 
29 #define TIMER_CLOCK_USE_EXT true
30 #define TIMER_CLOCK_EXT_HZ 1000000
31 #define TIMER_CLOCK_USE_APB false
32 
33 #define TIMER_REG_STATUS 0
34 #define TIMER_REG_RELOAD 1
35 #define TIMER_REG_MATCH_FIRST 2
36 #define TIMER_REG_MATCH_SECOND 3
37 
38 #define TIMER_FIRST_CAP_PULSE 4
39 
40 enum timer_ctrl_op {
41     op_enable = 0,
42     op_external_clock,
43     op_overflow_interrupt,
44     op_pulse_enable
45 };
46 
47 /*
48  * Minimum value of the reload register to filter out short period
49  * timers which have a noticeable impact in emulation. 5us should be
50  * enough, use 20us for "safety".
51  */
52 #define TIMER_MIN_NS (20 * SCALE_US)
53 
54 /**
55  * Avoid mutual references between AspeedTimerCtrlState and AspeedTimer
56  * structs, as it's a waste of memory. The ptimer BH callback needs to know
57  * whether a specific AspeedTimer is enabled, but this information is held in
58  * AspeedTimerCtrlState. So, provide a helper to hoist ourselves from an
59  * arbitrary AspeedTimer to AspeedTimerCtrlState.
60  */
61 static inline AspeedTimerCtrlState *timer_to_ctrl(AspeedTimer *t)
62 {
63     const AspeedTimer (*timers)[] = (void *)t - (t->id * sizeof(*t));
64     return container_of(timers, AspeedTimerCtrlState, timers);
65 }
66 
67 static inline bool timer_ctrl_status(AspeedTimer *t, enum timer_ctrl_op op)
68 {
69     return !!(timer_to_ctrl(t)->ctrl & BIT(t->id * TIMER_CTRL_BITS + op));
70 }
71 
72 static inline bool timer_enabled(AspeedTimer *t)
73 {
74     return timer_ctrl_status(t, op_enable);
75 }
76 
77 static inline bool timer_overflow_interrupt(AspeedTimer *t)
78 {
79     return timer_ctrl_status(t, op_overflow_interrupt);
80 }
81 
82 static inline bool timer_can_pulse(AspeedTimer *t)
83 {
84     return t->id >= TIMER_FIRST_CAP_PULSE;
85 }
86 
87 static inline bool timer_external_clock(AspeedTimer *t)
88 {
89     return timer_ctrl_status(t, op_external_clock);
90 }
91 
92 static inline uint32_t calculate_rate(struct AspeedTimer *t)
93 {
94     AspeedTimerCtrlState *s = timer_to_ctrl(t);
95 
96     return timer_external_clock(t) ? TIMER_CLOCK_EXT_HZ :
97         aspeed_scu_get_apb_freq(s->scu);
98 }
99 
100 static inline uint32_t calculate_ticks(struct AspeedTimer *t, uint64_t now_ns)
101 {
102     uint64_t delta_ns = now_ns - MIN(now_ns, t->start);
103     uint32_t rate = calculate_rate(t);
104     uint64_t ticks = muldiv64(delta_ns, rate, NANOSECONDS_PER_SECOND);
105 
106     return t->reload - MIN(t->reload, ticks);
107 }
108 
109 static uint32_t calculate_min_ticks(AspeedTimer *t, uint32_t value)
110 {
111     uint32_t rate = calculate_rate(t);
112     uint32_t min_ticks = muldiv64(TIMER_MIN_NS, rate, NANOSECONDS_PER_SECOND);
113 
114     return  value < min_ticks ? min_ticks : value;
115 }
116 
117 static inline uint64_t calculate_time(struct AspeedTimer *t, uint32_t ticks)
118 {
119     uint64_t delta_ns;
120     uint64_t delta_ticks;
121 
122     delta_ticks = t->reload - MIN(t->reload, ticks);
123     delta_ns = muldiv64(delta_ticks, NANOSECONDS_PER_SECOND, calculate_rate(t));
124 
125     return t->start + delta_ns;
126 }
127 
128 static inline uint32_t calculate_match(struct AspeedTimer *t, int i)
129 {
130     return t->match[i] < t->reload ? t->match[i] : 0;
131 }
132 
133 static uint64_t calculate_next(struct AspeedTimer *t)
134 {
135     uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
136     uint64_t next;
137 
138     /*
139      * We don't know the relationship between the values in the match
140      * registers, so sort using MAX/MIN/zero. We sort in that order as
141      * the timer counts down to zero.
142      */
143 
144     next = calculate_time(t, MAX(calculate_match(t, 0), calculate_match(t, 1)));
145     if (now < next) {
146         return next;
147     }
148 
149     next = calculate_time(t, MIN(calculate_match(t, 0), calculate_match(t, 1)));
150     if (now < next) {
151         return next;
152     }
153 
154     next = calculate_time(t, 0);
155     if (now < next) {
156         return next;
157     }
158 
159     /* We've missed all deadlines, fire interrupt and try again */
160     timer_del(&t->timer);
161 
162     if (timer_overflow_interrupt(t)) {
163         t->level = !t->level;
164         qemu_set_irq(t->irq, t->level);
165     }
166 
167     next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
168     t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
169 
170     return calculate_time(t, next);
171 }
172 
173 static void aspeed_timer_mod(AspeedTimer *t)
174 {
175     uint64_t next = calculate_next(t);
176     if (next) {
177         timer_mod(&t->timer, next);
178     }
179 }
180 
181 static void aspeed_timer_expire(void *opaque)
182 {
183     AspeedTimer *t = opaque;
184     bool interrupt = false;
185     uint32_t ticks;
186 
187     if (!timer_enabled(t)) {
188         return;
189     }
190 
191     ticks = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
192 
193     if (!ticks) {
194         interrupt = timer_overflow_interrupt(t) || !t->match[0] || !t->match[1];
195     } else if (ticks <= MIN(t->match[0], t->match[1])) {
196         interrupt = true;
197     } else if (ticks <= MAX(t->match[0], t->match[1])) {
198         interrupt = true;
199     }
200 
201     if (interrupt) {
202         t->level = !t->level;
203         qemu_set_irq(t->irq, t->level);
204     }
205 
206     aspeed_timer_mod(t);
207 }
208 
209 static uint64_t aspeed_timer_get_value(AspeedTimer *t, int reg)
210 {
211     uint64_t value;
212 
213     switch (reg) {
214     case TIMER_REG_STATUS:
215         if (timer_enabled(t)) {
216             value = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
217         } else {
218             value = t->reload;
219         }
220         break;
221     case TIMER_REG_RELOAD:
222         value = t->reload;
223         break;
224     case TIMER_REG_MATCH_FIRST:
225     case TIMER_REG_MATCH_SECOND:
226         value = t->match[reg - 2];
227         break;
228     default:
229         qemu_log_mask(LOG_UNIMP, "%s: Programming error: unexpected reg: %d\n",
230                       __func__, reg);
231         value = 0;
232         break;
233     }
234     return value;
235 }
236 
237 static uint64_t aspeed_timer_read(void *opaque, hwaddr offset, unsigned size)
238 {
239     AspeedTimerCtrlState *s = opaque;
240     const int reg = (offset & 0xf) / 4;
241     uint64_t value;
242 
243     switch (offset) {
244     case 0x30: /* Control Register */
245         value = s->ctrl;
246         break;
247     case 0x34: /* Control Register 2 */
248         value = s->ctrl2;
249         break;
250     case 0x00 ... 0x2c: /* Timers 1 - 4 */
251         value = aspeed_timer_get_value(&s->timers[(offset >> 4)], reg);
252         break;
253     case 0x40 ... 0x8c: /* Timers 5 - 8 */
254         value = aspeed_timer_get_value(&s->timers[(offset >> 4) - 1], reg);
255         break;
256     default:
257         value = ASPEED_TIMER_GET_CLASS(s)->read(s, offset);
258         break;
259     }
260     trace_aspeed_timer_read(offset, size, value);
261     return value;
262 }
263 
264 static void aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
265                                    uint32_t value)
266 {
267     AspeedTimer *t;
268     uint32_t old_reload;
269 
270     trace_aspeed_timer_set_value(timer, reg, value);
271     t = &s->timers[timer];
272     switch (reg) {
273     case TIMER_REG_RELOAD:
274         old_reload = t->reload;
275         t->reload = calculate_min_ticks(t, value);
276 
277         /* If the reload value was not previously set, or zero, and
278          * the current value is valid, try to start the timer if it is
279          * enabled.
280          */
281         if (old_reload || !t->reload) {
282             break;
283         }
284 
285     case TIMER_REG_STATUS:
286         if (timer_enabled(t)) {
287             uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
288             int64_t delta = (int64_t) value - (int64_t) calculate_ticks(t, now);
289             uint32_t rate = calculate_rate(t);
290 
291             if (delta >= 0) {
292                 t->start += muldiv64(delta, NANOSECONDS_PER_SECOND, rate);
293             } else {
294                 t->start -= muldiv64(-delta, NANOSECONDS_PER_SECOND, rate);
295             }
296             aspeed_timer_mod(t);
297         }
298         break;
299     case TIMER_REG_MATCH_FIRST:
300     case TIMER_REG_MATCH_SECOND:
301         t->match[reg - 2] = value;
302         if (timer_enabled(t)) {
303             aspeed_timer_mod(t);
304         }
305         break;
306     default:
307         qemu_log_mask(LOG_UNIMP, "%s: Programming error: unexpected reg: %d\n",
308                       __func__, reg);
309         break;
310     }
311 }
312 
313 /* Control register operations are broken out into helpers that can be
314  * explicitly called on aspeed_timer_reset(), but also from
315  * aspeed_timer_ctrl_op().
316  */
317 
318 static void aspeed_timer_ctrl_enable(AspeedTimer *t, bool enable)
319 {
320     trace_aspeed_timer_ctrl_enable(t->id, enable);
321     if (enable) {
322         t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
323         aspeed_timer_mod(t);
324     } else {
325         timer_del(&t->timer);
326     }
327 }
328 
329 static void aspeed_timer_ctrl_external_clock(AspeedTimer *t, bool enable)
330 {
331     trace_aspeed_timer_ctrl_external_clock(t->id, enable);
332 }
333 
334 static void aspeed_timer_ctrl_overflow_interrupt(AspeedTimer *t, bool enable)
335 {
336     trace_aspeed_timer_ctrl_overflow_interrupt(t->id, enable);
337 }
338 
339 static void aspeed_timer_ctrl_pulse_enable(AspeedTimer *t, bool enable)
340 {
341     if (timer_can_pulse(t)) {
342         trace_aspeed_timer_ctrl_pulse_enable(t->id, enable);
343     } else {
344         qemu_log_mask(LOG_GUEST_ERROR,
345                 "%s: Timer does not support pulse mode\n", __func__);
346     }
347 }
348 
349 /**
350  * Given the actions are fixed in number and completely described in helper
351  * functions, dispatch with a lookup table rather than manage control flow with
352  * a switch statement.
353  */
354 static void (*const ctrl_ops[])(AspeedTimer *, bool) = {
355     [op_enable] = aspeed_timer_ctrl_enable,
356     [op_external_clock] = aspeed_timer_ctrl_external_clock,
357     [op_overflow_interrupt] = aspeed_timer_ctrl_overflow_interrupt,
358     [op_pulse_enable] = aspeed_timer_ctrl_pulse_enable,
359 };
360 
361 /**
362  * Conditionally affect changes chosen by a timer's control bit.
363  *
364  * The aspeed_timer_ctrl_op() interface is convenient for the
365  * aspeed_timer_set_ctrl() function as the "no change" early exit can be
366  * calculated for all operations, which cleans up the caller code. However the
367  * interface isn't convenient for the reset function where we want to enter a
368  * specific state without artificially constructing old and new values that
369  * will fall through the change guard (and motivates extracting the actions
370  * out to helper functions).
371  *
372  * @t: The timer to manipulate
373  * @op: The type of operation to be performed
374  * @old: The old state of the timer's control bits
375  * @new: The incoming state for the timer's control bits
376  */
377 static void aspeed_timer_ctrl_op(AspeedTimer *t, enum timer_ctrl_op op,
378                                  uint8_t old, uint8_t new)
379 {
380     const uint8_t mask = BIT(op);
381     const bool enable = !!(new & mask);
382     const bool changed = ((old ^ new) & mask);
383     if (!changed) {
384         return;
385     }
386     ctrl_ops[op](t, enable);
387 }
388 
389 static void aspeed_timer_set_ctrl(AspeedTimerCtrlState *s, uint32_t reg)
390 {
391     int i;
392     int shift;
393     uint8_t t_old, t_new;
394     AspeedTimer *t;
395     const uint8_t enable_mask = BIT(op_enable);
396 
397     /* Handle a dependency between the 'enable' and remaining three
398      * configuration bits - i.e. if more than one bit in the control set has
399      * changed, including the 'enable' bit, then we want either disable the
400      * timer and perform configuration, or perform configuration and then
401      * enable the timer
402      */
403     for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
404         t = &s->timers[i];
405         shift = (i * TIMER_CTRL_BITS);
406         t_old = (s->ctrl >> shift) & TIMER_CTRL_MASK;
407         t_new = (reg >> shift) & TIMER_CTRL_MASK;
408 
409         /* If we are disabling, do so first */
410         if ((t_old & enable_mask) && !(t_new & enable_mask)) {
411             aspeed_timer_ctrl_enable(t, false);
412         }
413         aspeed_timer_ctrl_op(t, op_external_clock, t_old, t_new);
414         aspeed_timer_ctrl_op(t, op_overflow_interrupt, t_old, t_new);
415         aspeed_timer_ctrl_op(t, op_pulse_enable, t_old, t_new);
416         /* If we are enabling, do so last */
417         if (!(t_old & enable_mask) && (t_new & enable_mask)) {
418             aspeed_timer_ctrl_enable(t, true);
419         }
420     }
421     s->ctrl = reg;
422 }
423 
424 static void aspeed_timer_set_ctrl2(AspeedTimerCtrlState *s, uint32_t value)
425 {
426     trace_aspeed_timer_set_ctrl2(value);
427 }
428 
429 static void aspeed_timer_write(void *opaque, hwaddr offset, uint64_t value,
430                                unsigned size)
431 {
432     const uint32_t tv = (uint32_t)(value & 0xFFFFFFFF);
433     const int reg = (offset & 0xf) / 4;
434     AspeedTimerCtrlState *s = opaque;
435 
436     switch (offset) {
437     /* Control Registers */
438     case 0x30:
439         aspeed_timer_set_ctrl(s, tv);
440         break;
441     case 0x34:
442         aspeed_timer_set_ctrl2(s, tv);
443         break;
444     /* Timer Registers */
445     case 0x00 ... 0x2c:
446         aspeed_timer_set_value(s, (offset >> TIMER_NR_REGS), reg, tv);
447         break;
448     case 0x40 ... 0x8c:
449         aspeed_timer_set_value(s, (offset >> TIMER_NR_REGS) - 1, reg, tv);
450         break;
451     default:
452         ASPEED_TIMER_GET_CLASS(s)->write(s, offset, value);
453         break;
454     }
455 }
456 
457 static const MemoryRegionOps aspeed_timer_ops = {
458     .read = aspeed_timer_read,
459     .write = aspeed_timer_write,
460     .endianness = DEVICE_LITTLE_ENDIAN,
461     .valid.min_access_size = 4,
462     .valid.max_access_size = 4,
463     .valid.unaligned = false,
464 };
465 
466 static uint64_t aspeed_2400_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
467 {
468     uint64_t value;
469 
470     switch (offset) {
471     case 0x38:
472     case 0x3C:
473     default:
474         qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
475                 __func__, offset);
476         value = 0;
477         break;
478     }
479     return value;
480 }
481 
482 static void aspeed_2400_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
483                                     uint64_t value)
484 {
485     switch (offset) {
486     case 0x38:
487     case 0x3C:
488     default:
489         qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
490                 __func__, offset);
491         break;
492     }
493 }
494 
495 static uint64_t aspeed_2500_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
496 {
497     uint64_t value;
498 
499     switch (offset) {
500     case 0x38:
501     case 0x3C:
502     default:
503         qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
504                 __func__, offset);
505         value = 0;
506         break;
507     }
508     return value;
509 }
510 
511 static void aspeed_2500_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
512                                     uint64_t value)
513 {
514     switch (offset) {
515     case 0x38:
516     case 0x3C:
517     default:
518         qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
519                 __func__, offset);
520         break;
521     }
522 }
523 
524 static void aspeed_init_one_timer(AspeedTimerCtrlState *s, uint8_t id)
525 {
526     AspeedTimer *t = &s->timers[id];
527 
528     t->id = id;
529     timer_init_ns(&t->timer, QEMU_CLOCK_VIRTUAL, aspeed_timer_expire, t);
530 }
531 
532 static void aspeed_timer_realize(DeviceState *dev, Error **errp)
533 {
534     int i;
535     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
536     AspeedTimerCtrlState *s = ASPEED_TIMER(dev);
537     Object *obj;
538     Error *err = NULL;
539 
540     obj = object_property_get_link(OBJECT(dev), "scu", &err);
541     if (!obj) {
542         error_propagate_prepend(errp, err, "required link 'scu' not found: ");
543         return;
544     }
545     s->scu = ASPEED_SCU(obj);
546 
547     for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
548         aspeed_init_one_timer(s, i);
549         sysbus_init_irq(sbd, &s->timers[i].irq);
550     }
551     memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_timer_ops, s,
552                           TYPE_ASPEED_TIMER, 0x1000);
553     sysbus_init_mmio(sbd, &s->iomem);
554 }
555 
556 static void aspeed_timer_reset(DeviceState *dev)
557 {
558     int i;
559     AspeedTimerCtrlState *s = ASPEED_TIMER(dev);
560 
561     for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
562         AspeedTimer *t = &s->timers[i];
563         /* Explicitly call helpers to avoid any conditional behaviour through
564          * aspeed_timer_set_ctrl().
565          */
566         aspeed_timer_ctrl_enable(t, false);
567         aspeed_timer_ctrl_external_clock(t, TIMER_CLOCK_USE_APB);
568         aspeed_timer_ctrl_overflow_interrupt(t, false);
569         aspeed_timer_ctrl_pulse_enable(t, false);
570         t->level = 0;
571         t->reload = 0;
572         t->match[0] = 0;
573         t->match[1] = 0;
574     }
575     s->ctrl = 0;
576     s->ctrl2 = 0;
577 }
578 
579 static const VMStateDescription vmstate_aspeed_timer = {
580     .name = "aspeed.timer",
581     .version_id = 2,
582     .minimum_version_id = 2,
583     .fields = (VMStateField[]) {
584         VMSTATE_UINT8(id, AspeedTimer),
585         VMSTATE_INT32(level, AspeedTimer),
586         VMSTATE_TIMER(timer, AspeedTimer),
587         VMSTATE_UINT32(reload, AspeedTimer),
588         VMSTATE_UINT32_ARRAY(match, AspeedTimer, 2),
589         VMSTATE_END_OF_LIST()
590     }
591 };
592 
593 static const VMStateDescription vmstate_aspeed_timer_state = {
594     .name = "aspeed.timerctrl",
595     .version_id = 1,
596     .minimum_version_id = 1,
597     .fields = (VMStateField[]) {
598         VMSTATE_UINT32(ctrl, AspeedTimerCtrlState),
599         VMSTATE_UINT32(ctrl2, AspeedTimerCtrlState),
600         VMSTATE_STRUCT_ARRAY(timers, AspeedTimerCtrlState,
601                              ASPEED_TIMER_NR_TIMERS, 1, vmstate_aspeed_timer,
602                              AspeedTimer),
603         VMSTATE_END_OF_LIST()
604     }
605 };
606 
607 static void timer_class_init(ObjectClass *klass, void *data)
608 {
609     DeviceClass *dc = DEVICE_CLASS(klass);
610 
611     dc->realize = aspeed_timer_realize;
612     dc->reset = aspeed_timer_reset;
613     dc->desc = "ASPEED Timer";
614     dc->vmsd = &vmstate_aspeed_timer_state;
615 }
616 
617 static const TypeInfo aspeed_timer_info = {
618     .name = TYPE_ASPEED_TIMER,
619     .parent = TYPE_SYS_BUS_DEVICE,
620     .instance_size = sizeof(AspeedTimerCtrlState),
621     .class_init = timer_class_init,
622     .class_size = sizeof(AspeedTimerClass),
623     .abstract   = true,
624 };
625 
626 static void aspeed_2400_timer_class_init(ObjectClass *klass, void *data)
627 {
628     DeviceClass *dc = DEVICE_CLASS(klass);
629     AspeedTimerClass *awc = ASPEED_TIMER_CLASS(klass);
630 
631     dc->desc = "ASPEED 2400 Timer";
632     awc->read = aspeed_2400_timer_read;
633     awc->write = aspeed_2400_timer_write;
634 }
635 
636 static const TypeInfo aspeed_2400_timer_info = {
637     .name = TYPE_ASPEED_2400_TIMER,
638     .parent = TYPE_ASPEED_TIMER,
639     .class_init = aspeed_2400_timer_class_init,
640 };
641 
642 static void aspeed_2500_timer_class_init(ObjectClass *klass, void *data)
643 {
644     DeviceClass *dc = DEVICE_CLASS(klass);
645     AspeedTimerClass *awc = ASPEED_TIMER_CLASS(klass);
646 
647     dc->desc = "ASPEED 2500 Timer";
648     awc->read = aspeed_2500_timer_read;
649     awc->write = aspeed_2500_timer_write;
650 }
651 
652 static const TypeInfo aspeed_2500_timer_info = {
653     .name = TYPE_ASPEED_2500_TIMER,
654     .parent = TYPE_ASPEED_TIMER,
655     .class_init = aspeed_2500_timer_class_init,
656 };
657 
658 static void aspeed_timer_register_types(void)
659 {
660     type_register_static(&aspeed_timer_info);
661     type_register_static(&aspeed_2400_timer_info);
662     type_register_static(&aspeed_2500_timer_info);
663 }
664 
665 type_init(aspeed_timer_register_types)
666