在 2013-06-07五的 14:58 +0200,Andreas Färber写道:
> Introduce type constant and cast macro to obsolete DO_UPCAST().
> 
> Prepares for PIT realizefn.
> 
> Signed-off-by: Andreas Färber <afaer...@suse.de>
> ---
>  hw/i386/kvm/i8254.c      | 19 +++++++++++--------
>  include/hw/timer/i8254.h | 13 ++++++++-----
>  2 files changed, 19 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/i386/kvm/i8254.c b/hw/i386/kvm/i8254.c
> index da90711..4ac5551 100644
> --- a/hw/i386/kvm/i8254.c
> +++ b/hw/i386/kvm/i8254.c
> @@ -32,8 +32,11 @@
>  
>  #define CALIBRATION_ROUNDS   3
>  
> +#define KVM_PIT(obj) OBJECT_CHECK(KVMPITState, (obj), TYPE_KVM_I8254)
> +
>  typedef struct KVMPITState {
> -    PITCommonState pit;
> +    PITCommonState parent_obj;
> +
>      LostTickPolicy lost_tick_policy;
>      bool vm_stopped;
>      int64_t kernel_clock_offset;
> @@ -70,7 +73,7 @@ static void kvm_pit_update_clock_offset(KVMPITState *s)
>  
>  static void kvm_pit_get(PITCommonState *pit)
>  {
> -    KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit);
> +    KVMPITState *s = KVM_PIT(pit);

maybe we should keep the coding-style
either func(...) or func (...),
these patches blend them.

Thanks!

>      struct kvm_pit_state2 kpit;
>      struct kvm_pit_channel_state *kchan;
>      struct PITChannelState *sc;
> @@ -124,7 +127,7 @@ static void kvm_pit_get(PITCommonState *pit)
>  
>  static void kvm_pit_put(PITCommonState *pit)
>  {
> -    KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit);
> +    KVMPITState *s = KVM_PIT(pit);
>      struct kvm_pit_state2 kpit;
>      struct kvm_pit_channel_state *kchan;
>      struct PITChannelState *sc;
> @@ -200,7 +203,7 @@ static void kvm_pit_get_channel_info(PITCommonState *s, 
> PITChannelState *sc,
>  
>  static void kvm_pit_reset(DeviceState *dev)
>  {
> -    PITCommonState *s = DO_UPCAST(PITCommonState, dev.qdev, dev);
> +    PITCommonState *s = PIT_COMMON(dev);
>  
>      pit_reset_common(s);
>  
> @@ -229,14 +232,14 @@ static void kvm_pit_vm_state_change(void *opaque, int 
> running,
>          s->vm_stopped = false;
>      } else {
>          kvm_pit_update_clock_offset(s);
> -        kvm_pit_get(&s->pit);
> +        kvm_pit_get(PIT_COMMON(s));
>          s->vm_stopped = true;
>      }
>  }
>  
>  static int kvm_pit_initfn(PITCommonState *pit)
>  {
> -    KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit);
> +    KVMPITState *s = KVM_PIT(pit);
>      struct kvm_pit_config config = {
>          .flags = 0,
>      };
> @@ -282,7 +285,7 @@ static int kvm_pit_initfn(PITCommonState *pit)
>  }
>  
>  static Property kvm_pit_properties[] = {
> -    DEFINE_PROP_HEX32("iobase", KVMPITState, pit.iobase,  -1),
> +    DEFINE_PROP_HEX32("iobase", PITCommonState, iobase,  -1),
>      DEFINE_PROP_LOSTTICKPOLICY("lost_tick_policy", KVMPITState,
>                                 lost_tick_policy, LOST_TICK_DELAY),
>      DEFINE_PROP_END_OF_LIST(),
> @@ -303,7 +306,7 @@ static void kvm_pit_class_init(ObjectClass *klass, void 
> *data)
>  }
>  
>  static const TypeInfo kvm_pit_info = {
> -    .name          = "kvm-pit",
> +    .name          = TYPE_KVM_I8254,
>      .parent        = TYPE_PIT_COMMON,
>      .instance_size = sizeof(KVMPITState),
>      .class_init = kvm_pit_class_init,
> diff --git a/include/hw/timer/i8254.h b/include/hw/timer/i8254.h
> index 016f990..4349033 100644
> --- a/include/hw/timer/i8254.h
> +++ b/include/hw/timer/i8254.h
> @@ -38,6 +38,7 @@ typedef struct PITChannelInfo {
>  } PITChannelInfo;
>  
>  #define TYPE_I8254 "isa-pit"
> +#define TYPE_KVM_I8254 "kvm-pit"
>  
>  static inline ISADevice *pit_init(ISABus *bus, int base, int isa_irq,
>                                    qemu_irq alt_irq)
> @@ -57,13 +58,15 @@ static inline ISADevice *pit_init(ISABus *bus, int base, 
> int isa_irq,
>  
>  static inline ISADevice *kvm_pit_init(ISABus *bus, int base)
>  {
> -    ISADevice *dev;
> +    DeviceState *dev;
> +    ISADevice *d;
>  
> -    dev = isa_create(bus, "kvm-pit");
> -    qdev_prop_set_uint32(&dev->qdev, "iobase", base);
> -    qdev_init_nofail(&dev->qdev);
> +    d = isa_create(bus, TYPE_KVM_I8254);
> +    dev = DEVICE(d);
> +    qdev_prop_set_uint32(dev, "iobase", base);
> +    qdev_init_nofail(dev);
>  
> -    return dev;
> +    return d;
>  }
>  
>  void pit_set_gate(ISADevice *dev, int channel, int val);



Reply via email to