Lines Matching refs:t

62 static inline AspeedTimerCtrlState *timer_to_ctrl(AspeedTimer *t)  in timer_to_ctrl()  argument
64 const AspeedTimer (*timers)[] = (void *)t - (t->id * sizeof(*t)); in timer_to_ctrl()
68 static inline bool timer_ctrl_status(AspeedTimer *t, enum timer_ctrl_op op) in timer_ctrl_status() argument
70 return !!(timer_to_ctrl(t)->ctrl & BIT(t->id * TIMER_CTRL_BITS + op)); in timer_ctrl_status()
73 static inline bool timer_enabled(AspeedTimer *t) in timer_enabled() argument
75 return timer_ctrl_status(t, op_enable); in timer_enabled()
78 static inline bool timer_overflow_interrupt(AspeedTimer *t) in timer_overflow_interrupt() argument
80 return timer_ctrl_status(t, op_overflow_interrupt); in timer_overflow_interrupt()
83 static inline bool timer_can_pulse(AspeedTimer *t) in timer_can_pulse() argument
85 return t->id >= TIMER_FIRST_CAP_PULSE; in timer_can_pulse()
88 static inline bool timer_external_clock(AspeedTimer *t) in timer_external_clock() argument
90 return timer_ctrl_status(t, op_external_clock); in timer_external_clock()
93 static inline uint32_t calculate_rate(struct AspeedTimer *t) in calculate_rate() argument
95 AspeedTimerCtrlState *s = timer_to_ctrl(t); in calculate_rate()
97 return timer_external_clock(t) ? TIMER_CLOCK_EXT_HZ : in calculate_rate()
101 static inline uint32_t calculate_ticks(struct AspeedTimer *t, uint64_t now_ns) in calculate_ticks() argument
103 uint64_t delta_ns = now_ns - MIN(now_ns, t->start); in calculate_ticks()
104 uint32_t rate = calculate_rate(t); in calculate_ticks()
107 return t->reload - MIN(t->reload, ticks); in calculate_ticks()
110 static uint32_t calculate_min_ticks(AspeedTimer *t, uint32_t value) in calculate_min_ticks() argument
112 uint32_t rate = calculate_rate(t); in calculate_min_ticks()
118 static inline uint64_t calculate_time(struct AspeedTimer *t, uint32_t ticks) in calculate_time() argument
123 delta_ticks = t->reload - MIN(t->reload, ticks); in calculate_time()
124 delta_ns = muldiv64(delta_ticks, NANOSECONDS_PER_SECOND, calculate_rate(t)); in calculate_time()
126 return t->start + delta_ns; in calculate_time()
129 static inline uint32_t calculate_match(struct AspeedTimer *t, int i) in calculate_match() argument
131 return t->match[i] < t->reload ? t->match[i] : 0; in calculate_match()
134 static uint64_t calculate_next(struct AspeedTimer *t) in calculate_next() argument
145 next = calculate_time(t, MAX(calculate_match(t, 0), calculate_match(t, 1))); in calculate_next()
150 next = calculate_time(t, MIN(calculate_match(t, 0), calculate_match(t, 1))); in calculate_next()
155 next = calculate_time(t, 0); in calculate_next()
161 timer_del(&t->timer); in calculate_next()
163 if (timer_overflow_interrupt(t)) { in calculate_next()
164 AspeedTimerCtrlState *s = timer_to_ctrl(t); in calculate_next()
165 t->level = !t->level; in calculate_next()
166 s->irq_sts |= BIT(t->id); in calculate_next()
167 qemu_set_irq(t->irq, t->level); in calculate_next()
170 next = MAX(calculate_match(t, 0), calculate_match(t, 1)); in calculate_next()
171 t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); in calculate_next()
173 return calculate_time(t, next); in calculate_next()
176 static void aspeed_timer_mod(AspeedTimer *t) in aspeed_timer_mod() argument
178 uint64_t next = calculate_next(t); in aspeed_timer_mod()
180 timer_mod(&t->timer, next); in aspeed_timer_mod()
186 AspeedTimer *t = opaque; in aspeed_timer_expire() local
190 if (!timer_enabled(t)) { in aspeed_timer_expire()
194 ticks = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); in aspeed_timer_expire()
197 interrupt = timer_overflow_interrupt(t) || !t->match[0] || !t->match[1]; in aspeed_timer_expire()
198 } else if (ticks <= MIN(t->match[0], t->match[1])) { in aspeed_timer_expire()
200 } else if (ticks <= MAX(t->match[0], t->match[1])) { in aspeed_timer_expire()
205 AspeedTimerCtrlState *s = timer_to_ctrl(t); in aspeed_timer_expire()
206 t->level = !t->level; in aspeed_timer_expire()
207 s->irq_sts |= BIT(t->id); in aspeed_timer_expire()
208 qemu_set_irq(t->irq, t->level); in aspeed_timer_expire()
211 aspeed_timer_mod(t); in aspeed_timer_expire()
214 static uint64_t aspeed_timer_get_value(AspeedTimer *t, int reg) in aspeed_timer_get_value() argument
220 if (timer_enabled(t)) { in aspeed_timer_get_value()
221 value = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); in aspeed_timer_get_value()
223 value = t->reload; in aspeed_timer_get_value()
227 value = t->reload; in aspeed_timer_get_value()
231 value = t->match[reg - 2]; in aspeed_timer_get_value()
269 AspeedTimer *t; in aspeed_timer_set_value() local
273 t = &s->timers[timer]; in aspeed_timer_set_value()
276 old_reload = t->reload; in aspeed_timer_set_value()
277 t->reload = calculate_min_ticks(t, value); in aspeed_timer_set_value()
284 if (old_reload || !t->reload) { in aspeed_timer_set_value()
289 if (timer_enabled(t)) { in aspeed_timer_set_value()
291 int64_t delta = (int64_t) value - (int64_t) calculate_ticks(t, now); in aspeed_timer_set_value()
292 uint32_t rate = calculate_rate(t); in aspeed_timer_set_value()
295 t->start += muldiv64(delta, NANOSECONDS_PER_SECOND, rate); in aspeed_timer_set_value()
297 t->start -= muldiv64(-delta, NANOSECONDS_PER_SECOND, rate); in aspeed_timer_set_value()
299 aspeed_timer_mod(t); in aspeed_timer_set_value()
304 t->match[reg - 2] = value; in aspeed_timer_set_value()
305 if (timer_enabled(t)) { in aspeed_timer_set_value()
306 aspeed_timer_mod(t); in aspeed_timer_set_value()
322 static void aspeed_timer_ctrl_enable(AspeedTimer *t, bool enable) in aspeed_timer_ctrl_enable() argument
324 trace_aspeed_timer_ctrl_enable(t->id, enable); in aspeed_timer_ctrl_enable()
326 t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); in aspeed_timer_ctrl_enable()
327 aspeed_timer_mod(t); in aspeed_timer_ctrl_enable()
329 timer_del(&t->timer); in aspeed_timer_ctrl_enable()
333 static void aspeed_timer_ctrl_external_clock(AspeedTimer *t, bool enable) in aspeed_timer_ctrl_external_clock() argument
335 trace_aspeed_timer_ctrl_external_clock(t->id, enable); in aspeed_timer_ctrl_external_clock()
338 static void aspeed_timer_ctrl_overflow_interrupt(AspeedTimer *t, bool enable) in aspeed_timer_ctrl_overflow_interrupt() argument
340 trace_aspeed_timer_ctrl_overflow_interrupt(t->id, enable); in aspeed_timer_ctrl_overflow_interrupt()
343 static void aspeed_timer_ctrl_pulse_enable(AspeedTimer *t, bool enable) in aspeed_timer_ctrl_pulse_enable() argument
345 if (timer_can_pulse(t)) { in aspeed_timer_ctrl_pulse_enable()
346 trace_aspeed_timer_ctrl_pulse_enable(t->id, enable); in aspeed_timer_ctrl_pulse_enable()
381 static void aspeed_timer_ctrl_op(AspeedTimer *t, enum timer_ctrl_op op, in aspeed_timer_ctrl_op() argument
390 ctrl_ops[op](t, enable); in aspeed_timer_ctrl_op()
398 AspeedTimer *t; in aspeed_timer_set_ctrl() local
409 t = &s->timers[i]; in aspeed_timer_set_ctrl()
416 aspeed_timer_ctrl_enable(t, false); in aspeed_timer_set_ctrl()
418 aspeed_timer_ctrl_op(t, op_external_clock, t_old, t_new); in aspeed_timer_set_ctrl()
419 aspeed_timer_ctrl_op(t, op_overflow_interrupt, t_old, t_new); in aspeed_timer_set_ctrl()
420 aspeed_timer_ctrl_op(t, op_pulse_enable, t_old, t_new); in aspeed_timer_set_ctrl()
423 aspeed_timer_ctrl_enable(t, true); in aspeed_timer_set_ctrl()
598 AspeedTimer *t = &s->timers[id]; in aspeed_init_one_timer() local
600 t->id = id; in aspeed_init_one_timer()
601 timer_init_ns(&t->timer, QEMU_CLOCK_VIRTUAL, aspeed_timer_expire, t); in aspeed_init_one_timer()
627 AspeedTimer *t = &s->timers[i]; in aspeed_timer_reset() local
632 aspeed_timer_ctrl_enable(t, false); in aspeed_timer_reset()
633 aspeed_timer_ctrl_external_clock(t, TIMER_CLOCK_USE_APB); in aspeed_timer_reset()
634 aspeed_timer_ctrl_overflow_interrupt(t, false); in aspeed_timer_reset()
635 aspeed_timer_ctrl_pulse_enable(t, false); in aspeed_timer_reset()
636 t->level = 0; in aspeed_timer_reset()
637 t->reload = 0; in aspeed_timer_reset()
638 t->match[0] = 0; in aspeed_timer_reset()
639 t->match[1] = 0; in aspeed_timer_reset()