Lines Matching refs:h
58 #define hpet_tick_to_ns(h, tick) \ argument
59 ((s_time_t)((((tick) > (h)->hpet_to_ns_limit) ? \
60 ~0ULL : (tick) * (h)->hpet_to_ns_scale) >> 10))
62 #define timer_config(h, n) (h->hpet.timers[n].config) argument
63 #define timer_enabled(h, n) (timer_config(h, n) & HPET_TN_ENABLE) argument
64 #define timer_is_periodic(h, n) (timer_config(h, n) & HPET_TN_PERIODIC) argument
65 #define timer_is_32bit(h, n) (timer_config(h, n) & HPET_TN_32BIT) argument
66 #define hpet_enabled(h) (h->hpet.config & HPET_CFG_ENABLE) argument
67 #define timer_level(h, n) (timer_config(h, n) & HPET_TN_LEVEL) argument
69 #define timer_int_route(h, n) \ argument
70 ((timer_config(h, n) & HPET_TN_ROUTE) >> HPET_TN_ROUTE_SHIFT)
72 #define timer_int_route_cap(h, n) \ argument
73 ((timer_config(h, n) & HPET_TN_INT_ROUTE_CAP_MASK) \
76 static inline uint64_t hpet_read_maincounter(HPETState *h, uint64_t guest_time) in hpet_read_maincounter() argument
78 ASSERT(rw_is_locked(&h->lock)); in hpet_read_maincounter()
80 if ( hpet_enabled(h) ) in hpet_read_maincounter()
81 return guest_time + h->mc_offset; in hpet_read_maincounter()
83 return h->hpet.mc64; in hpet_read_maincounter()
86 static uint64_t hpet_get_comparator(HPETState *h, unsigned int tn, in hpet_get_comparator() argument
92 ASSERT(rw_is_write_locked(&h->lock)); in hpet_get_comparator()
94 comparator = h->hpet.comparator64[tn]; in hpet_get_comparator()
95 if ( hpet_enabled(h) && timer_is_periodic(h, tn) ) in hpet_get_comparator()
98 uint64_t period = h->hpet.period[tn]; in hpet_get_comparator()
101 elapsed = hpet_read_maincounter(h, guest_time) - comparator; in hpet_get_comparator()
105 h->hpet.comparator64[tn] = comparator; in hpet_get_comparator()
111 if ( timer_is_32bit(h, tn) ) in hpet_get_comparator()
113 h->hpet.timers[tn].cmp = comparator; in hpet_get_comparator()
116 static inline uint64_t hpet_read64(HPETState *h, unsigned long addr, in hpet_read64() argument
124 return h->hpet.capability; in hpet_read64()
126 return h->hpet.config; in hpet_read64()
128 return h->hpet.isr; in hpet_read64()
130 return hpet_read_maincounter(h, guest_time); in hpet_read64()
134 return h->hpet.timers[HPET_TN(CFG, addr)].config; in hpet_read64()
138 return hpet_get_comparator(h, HPET_TN(CMP, addr), guest_time); in hpet_read64()
142 return h->hpet.timers[HPET_TN(ROUTE, addr)].fsb; in hpet_read64()
170 HPETState *h = vcpu_vhpet(v); in hpet_read() local
191 read_lock(&h->lock); in hpet_read()
193 write_lock(&h->lock); in hpet_read()
195 val = hpet_read64(h, addr, guest_time_hpet(h)); in hpet_read()
198 read_unlock(&h->lock); in hpet_read()
200 write_unlock(&h->lock); in hpet_read()
211 static void hpet_stop_timer(HPETState *h, unsigned int tn, in hpet_stop_timer() argument
215 ASSERT(rw_is_write_locked(&h->lock)); in hpet_stop_timer()
217 destroy_periodic_time(&h->pt[tn]); in hpet_stop_timer()
220 hpet_get_comparator(h, tn, guest_time); in hpet_stop_timer()
225 #define HPET_TINY_TIME_SPAN ((h->stime_freq >> 10) / STIME_PER_HPET_TICK)
227 static void hpet_set_timer(HPETState *h, unsigned int tn, in hpet_set_timer() argument
235 ASSERT(rw_is_write_locked(&h->lock)); in hpet_set_timer()
237 if ( (tn == 0) && (h->hpet.config & HPET_CFG_LEGACY) ) in hpet_set_timer()
241 pit_stop_channel0_irq(&vhpet_domain(h)->arch.vpit); in hpet_set_timer()
244 if ( !timer_enabled(h, tn) ) in hpet_set_timer()
247 tn_cmp = hpet_get_comparator(h, tn, guest_time); in hpet_set_timer()
248 cur_tick = hpet_read_maincounter(h, guest_time); in hpet_set_timer()
249 if ( timer_is_32bit(h, tn) ) in hpet_set_timer()
264 diff = (timer_is_32bit(h, tn) && (-diff > HPET_TINY_TIME_SPAN)) in hpet_set_timer()
267 if ( (tn <= 1) && (h->hpet.config & HPET_CFG_LEGACY) ) in hpet_set_timer()
273 irq = timer_int_route(h, tn); in hpet_set_timer()
281 oneshot = !timer_is_periodic(h, tn); in hpet_set_timer()
283 TRC_PAR_LONG(hpet_tick_to_ns(h, diff)), in hpet_set_timer()
285 hpet_tick_to_ns(h, h->hpet.period[tn]))); in hpet_set_timer()
286 create_periodic_time(vhpet_vcpu(h), &h->pt[tn], in hpet_set_timer()
287 hpet_tick_to_ns(h, diff), in hpet_set_timer()
288 oneshot ? 0 : hpet_tick_to_ns(h, h->hpet.period[tn]), in hpet_set_timer()
304 HPETState *h = vcpu_vhpet(v); in hpet_write() local
324 write_lock(&h->lock); in hpet_write()
326 guest_time = guest_time_hpet(h); in hpet_write()
327 old_val = hpet_read64(h, addr, guest_time); in hpet_write()
337 h->hpet.config = hpet_fixup_reg(new_val, old_val, 0x3); in hpet_write()
342 h->mc_offset = h->hpet.mc64 - guest_time; in hpet_write()
345 h->hpet.comparator64[i] = in hpet_write()
346 h->hpet.timers[i].config & HPET_TN_32BIT ? in hpet_write()
347 (uint32_t)h->hpet.timers[i].cmp : in hpet_write()
348 h->hpet.timers[i].cmp; in hpet_write()
349 if ( timer_enabled(h, i) ) in hpet_write()
356 h->hpet.mc64 = h->mc_offset + guest_time; in hpet_write()
358 if ( timer_enabled(h, i) ) in hpet_write()
364 h->hpet.mc64 = new_val; in hpet_write()
365 if ( hpet_enabled(h) ) in hpet_write()
370 if ( timer_enabled(h, i) ) in hpet_write()
380 h->hpet.timers[tn].config = hpet_fixup_reg(new_val, old_val, 0x3f4e); in hpet_write()
382 if ( timer_level(h, tn) ) in hpet_write()
392 h->hpet.timers[tn].cmp = (uint32_t)h->hpet.timers[tn].cmp; in hpet_write()
393 h->hpet.period[tn] = (uint32_t)h->hpet.period[tn]; in hpet_write()
395 if ( hpet_enabled(h) ) in hpet_write()
423 if ( timer_is_periodic(h, tn) && in hpet_write()
424 !(h->hpet.timers[tn].config & HPET_TN_SETVAL) ) in hpet_write()
426 uint64_t max_period = (timer_is_32bit(h, tn) ? ~0u : ~0ull) >> 1; in hpet_write()
433 if ( hpet_tick_to_ns(h, new_val) < MICROSECS(100) ) in hpet_write()
434 new_val = (MICROSECS(100) << 10) / h->hpet_to_ns_scale; in hpet_write()
437 h->hpet.period[tn] = new_val; in hpet_write()
451 h->hpet.timers[tn].config &= ~HPET_TN_SETVAL; in hpet_write()
452 h->hpet.comparator64[tn] = new_val; in hpet_write()
454 if ( timer_is_32bit(h, tn) ) in hpet_write()
456 h->hpet.timers[tn].cmp = new_val; in hpet_write()
458 if ( hpet_enabled(h) && timer_enabled(h, tn) ) in hpet_write()
466 h->hpet.timers[tn].fsb = new_val; in hpet_write()
479 hpet_stop_timer(h, i, guest_time); in hpet_write()
486 hpet_set_timer(h, i, guest_time); in hpet_write()
493 write_unlock(&h->lock); in hpet_write()
512 static int hpet_save(struct domain *d, hvm_domain_context_t *h) in hpet_save() argument
531 rc = _hvm_init_entry(h, HVM_SAVE_CODE(HPET), 0, HVM_SAVE_LENGTH(HPET)); in hpet_save()
534 struct hvm_hw_hpet *rec = (struct hvm_hw_hpet *)&h->data[h->cur]; in hpet_save()
535 h->cur += HVM_SAVE_LENGTH(HPET); in hpet_save()
574 static int hpet_load(struct domain *d, hvm_domain_context_t *h) in hpet_load() argument
588 if ( _hvm_check_entry(h, HVM_SAVE_CODE(HPET), HVM_SAVE_LENGTH(HPET), 1) ) in hpet_load()
594 rec = (struct hvm_hw_hpet *)&h->data[h->cur]; in hpet_load()
595 h->cur += HVM_SAVE_LENGTH(HPET); in hpet_load()
638 static void hpet_set(HPETState *h) in hpet_set() argument
642 memset(h, 0, sizeof(HPETState)); in hpet_set()
644 rwlock_init(&h->lock); in hpet_set()
646 h->stime_freq = S_TO_NS; in hpet_set()
648 h->hpet_to_ns_scale = ((S_TO_NS * STIME_PER_HPET_TICK) << 10) / h->stime_freq; in hpet_set()
649 h->hpet_to_ns_limit = ~0ULL / h->hpet_to_ns_scale; in hpet_set()
651 h->hpet.capability = 0x80860001ULL | in hpet_set()
657 h->hpet.capability |= ((S_TO_FS*STIME_PER_HPET_TICK/h->stime_freq) << 32); in hpet_set()
661 h->hpet.timers[i].config = in hpet_set()
663 h->hpet.timers[i].cmp = ~0ULL; in hpet_set()
664 h->hpet.comparator64[i] = ~0ULL; in hpet_set()
665 h->pt[i].source = PTSRC_isa; in hpet_set()
682 HPETState *h = domain_vhpet(d); in hpet_deinit() local
687 write_lock(&h->lock); in hpet_deinit()
689 if ( hpet_enabled(h) ) in hpet_deinit()
691 uint64_t guest_time = guest_time_hpet(h); in hpet_deinit()
694 if ( timer_enabled(h, i) ) in hpet_deinit()
695 hpet_stop_timer(h, i, guest_time); in hpet_deinit()
698 write_unlock(&h->lock); in hpet_deinit()