debuggers.hg

changeset 19944:2fadef1b008f

x86,hvm: cleanup hpet.c vcpu handling same as i8254.c/rtc.c

- introduce macros: domain_vhpet, vcpu_vhpet, vhpet_domain, vhpet_vcpu
- remove *vcpu field from struct HPETState
- modify guest_time_hpet() takes *vhpet instead of *vcpu as 1st
- argument

Signed-off-by: Kouya Shimura <kouya@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jul 07 14:08:47 2009 +0100 (2009-07-07)
parents 7ce4f3675c9b
children a29bb4efff00
files xen/arch/x86/hvm/hpet.c xen/include/asm-x86/hvm/vpt.h
line diff
     1.1 --- a/xen/arch/x86/hvm/hpet.c	Tue Jul 07 14:07:08 2009 +0100
     1.2 +++ b/xen/arch/x86/hvm/hpet.c	Tue Jul 07 14:08:47 2009 +0100
     1.3 @@ -24,6 +24,12 @@
     1.4  #include <xen/sched.h>
     1.5  #include <xen/event.h>
     1.6  
     1.7 +#define domain_vhpet(d)    (&(d)->arch.hvm_domain.pl_time.vhpet)
     1.8 +#define vcpu_vhpet(vcpu)   (domain_vhpet((vcpu)->domain))
     1.9 +#define vhpet_domain(hpet) (container_of((hpet), struct domain, \
    1.10 +                                         arch.hvm_domain.pl_time.vhpet))
    1.11 +#define vhpet_vcpu(hpet)   (vhpet_domain(hpet)->vcpu[0])
    1.12 +
    1.13  #define HPET_BASE_ADDRESS   0xfed00000ULL
    1.14  #define HPET_MMAP_SIZE      1024
    1.15  #define S_TO_NS  1000000000ULL           /* 1s  = 10^9  ns */
    1.16 @@ -31,7 +37,8 @@
    1.17  
    1.18  /* Frequency_of_Xen_systeme_time / frequency_of_HPET = 16 */
    1.19  #define STIME_PER_HPET_TICK 16
    1.20 -#define guest_time_hpet(v) (hvm_get_guest_time(v) / STIME_PER_HPET_TICK)
    1.21 +#define guest_time_hpet(hpet) \
    1.22 +    (hvm_get_guest_time(vhpet_vcpu(hpet)) / STIME_PER_HPET_TICK)
    1.23  
    1.24  #define HPET_ID         0x000
    1.25  #define HPET_PERIOD     0x004
    1.26 @@ -94,7 +101,7 @@ static inline uint64_t hpet_read_maincou
    1.27      ASSERT(spin_is_locked(&h->lock));
    1.28  
    1.29      if ( hpet_enabled(h) )
    1.30 -        return guest_time_hpet(h->vcpu) + h->mc_offset;
    1.31 +        return guest_time_hpet(h) + h->mc_offset;
    1.32      else 
    1.33          return h->hpet.mc64;
    1.34  }
    1.35 @@ -176,7 +183,7 @@ static int hpet_read(
    1.36      struct vcpu *v, unsigned long addr, unsigned long length,
    1.37      unsigned long *pval)
    1.38  {
    1.39 -    HPETState *h = &v->domain->arch.hvm_domain.pl_time.vhpet;
    1.40 +    HPETState *h = vcpu_vhpet(v);
    1.41      unsigned long result;
    1.42      uint64_t val;
    1.43  
    1.44 @@ -230,7 +237,7 @@ static void hpet_set_timer(HPETState *h,
    1.45      {
    1.46          /* HPET specification requires PIT shouldn't generate
    1.47           * interrupts if LegacyReplacementRoute is set for timer0 */
    1.48 -        PITState *pit = &h->vcpu->domain->arch.hvm_domain.pl_time.vpit;
    1.49 +        PITState *pit = &vhpet_domain(h)->arch.hvm_domain.pl_time.vpit;
    1.50          pit_stop_channel0_irq(pit);
    1.51      }
    1.52  
    1.53 @@ -272,7 +279,7 @@ static void hpet_set_timer(HPETState *h,
    1.54       * being enabled (now).
    1.55       */
    1.56      oneshot = !timer_is_periodic(h, tn);
    1.57 -    create_periodic_time(h->vcpu, &h->pt[tn],
    1.58 +    create_periodic_time(vhpet_vcpu(h), &h->pt[tn],
    1.59                           hpet_tick_to_ns(h, diff),
    1.60                           oneshot ? 0 : hpet_tick_to_ns(h, h->hpet.period[tn]),
    1.61                           irq, NULL, NULL);
    1.62 @@ -290,7 +297,7 @@ static int hpet_write(
    1.63      struct vcpu *v, unsigned long addr,
    1.64      unsigned long length, unsigned long val)
    1.65  {
    1.66 -    HPETState *h = &v->domain->arch.hvm_domain.pl_time.vhpet;
    1.67 +    HPETState *h = vcpu_vhpet(v);
    1.68      uint64_t old_val, new_val;
    1.69      int tn, i;
    1.70  
    1.71 @@ -323,7 +330,7 @@ static int hpet_write(
    1.72          if ( !(old_val & HPET_CFG_ENABLE) && (new_val & HPET_CFG_ENABLE) )
    1.73          {
    1.74              /* Enable main counter and interrupt generation. */
    1.75 -            h->mc_offset = h->hpet.mc64 - guest_time_hpet(h->vcpu);
    1.76 +            h->mc_offset = h->hpet.mc64 - guest_time_hpet(h);
    1.77              for ( i = 0; i < HPET_TIMER_NUM; i++ )
    1.78              {
    1.79                  h->hpet.comparator64[i] =
    1.80 @@ -337,7 +344,7 @@ static int hpet_write(
    1.81          else if ( (old_val & HPET_CFG_ENABLE) && !(new_val & HPET_CFG_ENABLE) )
    1.82          {
    1.83              /* Halt main counter and disable interrupt generation. */
    1.84 -            h->hpet.mc64 = h->mc_offset + guest_time_hpet(h->vcpu);
    1.85 +            h->hpet.mc64 = h->mc_offset + guest_time_hpet(h);
    1.86              for ( i = 0; i < HPET_TIMER_NUM; i++ )
    1.87                  if ( timer_enabled(h, i) )
    1.88                      set_stop_timer(i);
    1.89 @@ -487,13 +494,13 @@ struct hvm_mmio_handler hpet_mmio_handle
    1.90  
    1.91  static int hpet_save(struct domain *d, hvm_domain_context_t *h)
    1.92  {
    1.93 -    HPETState *hp = &d->arch.hvm_domain.pl_time.vhpet;
    1.94 +    HPETState *hp = domain_vhpet(d);
    1.95      int rc;
    1.96  
    1.97      spin_lock(&hp->lock);
    1.98  
    1.99      /* Write the proper value into the main counter */
   1.100 -    hp->hpet.mc64 = hp->mc_offset + guest_time_hpet(hp->vcpu);
   1.101 +    hp->hpet.mc64 = hp->mc_offset + guest_time_hpet(hp);
   1.102  
   1.103      /* Save the HPET registers */
   1.104      rc = _hvm_init_entry(h, HVM_SAVE_CODE(HPET), 0, HVM_SAVE_LENGTH(HPET));
   1.105 @@ -531,7 +538,7 @@ static int hpet_save(struct domain *d, h
   1.106  
   1.107  static int hpet_load(struct domain *d, hvm_domain_context_t *h)
   1.108  {
   1.109 -    HPETState *hp = &d->arch.hvm_domain.pl_time.vhpet;
   1.110 +    HPETState *hp = domain_vhpet(d);
   1.111      struct hvm_hw_hpet *rec;
   1.112      uint64_t cmp;
   1.113      int i;
   1.114 @@ -572,7 +579,7 @@ static int hpet_load(struct domain *d, h
   1.115  #undef C
   1.116      
   1.117      /* Recalculate the offset between the main counter and guest time */
   1.118 -    hp->mc_offset = hp->hpet.mc64 - guest_time_hpet(hp->vcpu);
   1.119 +    hp->mc_offset = hp->hpet.mc64 - guest_time_hpet(hp);
   1.120  
   1.121      /* restart all timers */
   1.122  
   1.123 @@ -590,14 +597,13 @@ HVM_REGISTER_SAVE_RESTORE(HPET, hpet_sav
   1.124  
   1.125  void hpet_init(struct vcpu *v)
   1.126  {
   1.127 -    HPETState *h = &v->domain->arch.hvm_domain.pl_time.vhpet;
   1.128 +    HPETState *h = vcpu_vhpet(v);
   1.129      int i;
   1.130  
   1.131      memset(h, 0, sizeof(HPETState));
   1.132  
   1.133      spin_lock_init(&h->lock);
   1.134  
   1.135 -    h->vcpu = v;
   1.136      h->stime_freq = S_TO_NS;
   1.137  
   1.138      h->hpet_to_ns_scale = ((S_TO_NS * STIME_PER_HPET_TICK) << 10) / h->stime_freq;
   1.139 @@ -622,7 +628,7 @@ void hpet_init(struct vcpu *v)
   1.140  void hpet_deinit(struct domain *d)
   1.141  {
   1.142      int i;
   1.143 -    HPETState *h = &d->arch.hvm_domain.pl_time.vhpet;
   1.144 +    HPETState *h = domain_vhpet(d);
   1.145  
   1.146      spin_lock(&h->lock);
   1.147  
     2.1 --- a/xen/include/asm-x86/hvm/vpt.h	Tue Jul 07 14:07:08 2009 +0100
     2.2 +++ b/xen/include/asm-x86/hvm/vpt.h	Tue Jul 07 14:08:47 2009 +0100
     2.3 @@ -92,7 +92,6 @@ struct hpet_registers {
     2.4  
     2.5  typedef struct HPETState {
     2.6      struct hpet_registers hpet;
     2.7 -    struct vcpu *vcpu;
     2.8      uint64_t stime_freq;
     2.9      uint64_t hpet_to_ns_scale; /* hpet ticks to ns (multiplied by 2^10) */
    2.10      uint64_t hpet_to_ns_limit; /* max hpet ticks convertable to ns      */