ia64/xen-unstable

view xen/include/asm-x86/hvm/vpt.h @ 16603:4553bc1087d9

hvm: Reduce vpt.c dependencies on external timer details.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Dec 12 15:41:20 2007 +0000 (2007-12-12)
parents f2f7c92bf1c1
children 9ff64d045e61
line source
1 /*
2 * vpt.h: Virtual Platform Timer definitions
3 *
4 * Copyright (c) 2004, Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place - Suite 330, Boston, MA 02111-1307 USA.
18 */
20 #ifndef __ASM_X86_HVM_VPT_H__
21 #define __ASM_X86_HVM_VPT_H__
23 #include <xen/config.h>
24 #include <xen/init.h>
25 #include <xen/lib.h>
26 #include <xen/time.h>
27 #include <xen/errno.h>
28 #include <xen/time.h>
29 #include <xen/timer.h>
30 #include <xen/list.h>
31 #include <asm/hvm/vpic.h>
32 #include <asm/hvm/irq.h>
33 #include <public/hvm/save.h>
35 struct HPETState;
36 struct HPET_timer_fn_info {
37 struct HPETState *hs;
38 unsigned int tn;
39 };
41 struct hpet_registers {
42 /* Memory-mapped, software visible registers */
43 uint64_t capability; /* capabilities */
44 uint64_t config; /* configuration */
45 uint64_t isr; /* interrupt status reg */
46 uint64_t mc64; /* main counter */
47 struct { /* timers */
48 uint64_t config; /* configuration/cap */
49 uint64_t cmp; /* comparator */
50 uint64_t fsb; /* FSB route, not supported now */
51 } timers[HPET_TIMER_NUM];
53 /* Hidden register state */
54 uint64_t period[HPET_TIMER_NUM]; /* Last value written to comparator */
55 };
57 typedef struct HPETState {
58 struct hpet_registers hpet;
59 struct vcpu *vcpu;
60 uint64_t tsc_freq;
61 uint64_t mc_offset;
62 struct timer timers[HPET_TIMER_NUM];
63 struct HPET_timer_fn_info timer_fn_info[HPET_TIMER_NUM];
64 spinlock_t lock;
65 } HPETState;
68 /*
69 * Abstract layer of periodic time, one short time.
70 */
71 typedef void time_cb(struct vcpu *v, void *opaque);
73 struct periodic_time {
74 struct list_head list;
75 bool_t on_list;
76 bool_t one_shot;
77 bool_t do_not_freeze;
78 bool_t irq_issued;
79 #define PTSRC_isa 1 /* ISA time source */
80 #define PTSRC_lapic 2 /* LAPIC time source */
81 u8 source; /* PTSRC_ */
82 u8 irq;
83 struct vcpu *vcpu; /* vcpu timer interrupt delivers to */
84 u32 pending_intr_nr; /* pending timer interrupts */
85 u64 period; /* frequency in ns */
86 u64 period_cycles; /* frequency in cpu cycles */
87 s_time_t scheduled; /* scheduled timer interrupt */
88 u64 last_plt_gtime; /* platform time when last IRQ is injected */
89 struct timer timer; /* ac_timer */
90 time_cb *cb;
91 void *priv; /* point back to platform time source */
92 };
95 #define PIT_FREQ 1193181
96 #define PIT_BASE 0x40
98 typedef struct PITState {
99 /* Hardware state */
100 struct hvm_hw_pit hw;
101 /* Last time the counters read zero, for calcuating counter reads */
102 int64_t count_load_time[3];
103 /* Channel 0 IRQ handling. */
104 struct periodic_time pt0;
105 spinlock_t lock;
106 } PITState;
108 typedef struct RTCState {
109 /* Hardware state */
110 struct hvm_hw_rtc hw;
111 /* RTC's idea of the current time */
112 struct tm current_tm;
113 /* second update */
114 int64_t next_second_time;
115 struct timer second_timer;
116 struct timer second_timer2;
117 struct periodic_time pt;
118 int32_t time_offset_seconds;
119 spinlock_t lock;
120 } RTCState;
122 #define FREQUENCE_PMTIMER 3579545 /* Timer should run at 3.579545 MHz */
123 typedef struct PMTState {
124 struct hvm_hw_pmtimer pm; /* 32bit timer value */
125 struct vcpu *vcpu; /* Keeps sync with this vcpu's guest-time */
126 uint64_t last_gtime; /* Last (guest) time we updated the timer */
127 uint64_t scale; /* Multiplier to get from tsc to timer ticks */
128 struct timer timer; /* To make sure we send SCIs */
129 spinlock_t lock;
130 } PMTState;
132 struct pl_time { /* platform time */
133 struct PITState vpit;
134 struct RTCState vrtc;
135 struct HPETState vhpet;
136 struct PMTState vpmt;
137 };
139 #define ticks_per_sec(v) (v->domain->arch.hvm_domain.tsc_frequency)
141 void pt_save_timer(struct vcpu *v);
142 void pt_restore_timer(struct vcpu *v);
143 void pt_update_irq(struct vcpu *v);
144 void pt_intr_post(struct vcpu *v, struct hvm_intack intack);
145 void pt_reset(struct vcpu *v);
146 void pt_migrate(struct vcpu *v);
148 /* Is given periodic timer active? */
149 #define pt_active(pt) ((pt)->on_list)
151 /*
152 * Create/destroy a periodic (or one-shot!) timer.
153 * The given periodic timer structure must be initialised with zero bytes,
154 * except for the 'source' field which must be initialised with the
155 * correct PTSRC_ value. The initialised timer structure can then be passed
156 * to {create,destroy}_periodic_time() and number of times and in any order.
157 * Note that, for a given periodic timer, invocations of these functions MUST
158 * be serialised.
159 */
160 void create_periodic_time(
161 struct vcpu *v, struct periodic_time *pt, uint64_t period,
162 uint8_t irq, char one_shot, time_cb *cb, void *data);
163 void destroy_periodic_time(struct periodic_time *pt);
165 int pv_pit_handler(int port, int data, int write);
166 void pit_init(struct vcpu *v, unsigned long cpu_khz);
167 void pit_stop_channel0_irq(PITState * pit);
168 void pit_deinit(struct domain *d);
169 void rtc_init(struct vcpu *v, int base);
170 void rtc_migrate_timers(struct vcpu *v);
171 void rtc_deinit(struct domain *d);
172 void pmtimer_init(struct vcpu *v);
173 void pmtimer_deinit(struct domain *d);
175 void hpet_migrate_timers(struct vcpu *v);
176 void hpet_init(struct vcpu *v);
177 void hpet_deinit(struct domain *d);
179 #endif /* __ASM_X86_HVM_VPT_H__ */