Patchwork [39/39] tpm: move add/del_subregion to realize/unrealize

login
register
mail settings
Submitter Paolo Bonzini
Date June 4, 2013, 6:52 p.m.
Message ID <1370371954-8479-40-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/248848/
State New
Headers show

Comments

Paolo Bonzini - June 4, 2013, 6:52 p.m.
Only do init/destroy in instance_init/finalize.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/tpm/tpm_tis.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
Andreas Färber - June 7, 2013, 8:02 a.m.
Am 04.06.2013 20:52, schrieb Paolo Bonzini:
> Only do init/destroy in instance_init/finalize.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  hw/tpm/tpm_tis.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
> index d4d8152..303d778 100644
> --- a/hw/tpm/tpm_tis.c
> +++ b/hw/tpm/tpm_tis.c
> @@ -881,24 +881,29 @@ static void tpm_tis_realizefn(DeviceState *dev, Error **errp)

ISADevice *d = ISA_DEVICE(dev);

>      tis->bh = qemu_bh_new(tpm_tis_receive_bh, s);
>  
>      isa_init_irq(&s->busdev, &tis->irq, tis->irq_num);

isa_init_irq(d, ...

> +    memory_region_add_subregion(isa_address_space(&s->busdev), TPM_TIS_ADDR_BASE,
> +                                &s->mmio);

isa_address_space(d)

> +}
> +
> +static void tpm_tis_unrealizefn(DeviceState *dev, Error **errp)
> +{
> +    TPMState *s = TPM(dev);
> +
> +    memory_region_del_subregion(get_system_memory(), &s->mmio);
>  }
>  
>  static void tpm_tis_initfn(Object *obj)
>  {
> -    ISADevice *dev = ISA_DEVICE(obj);
>      TPMState *s = TPM(obj);
>  
>      memory_region_init_io(&s->mmio, &tpm_tis_memory_ops, s, "tpm-tis-mmio",
>                            TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT);
> -    memory_region_add_subregion(isa_address_space(dev), TPM_TIS_ADDR_BASE,
> -                                &s->mmio);

Regression from here.

Andreas

>  }
>  
>  static void tpm_tis_uninitfn(Object *obj)
>  {
>      TPMState *s = TPM(obj);
>  
> -    memory_region_del_subregion(get_system_memory(), &s->mmio);
>      memory_region_destroy(&s->mmio);
>  }
>  
> @@ -907,6 +912,7 @@ static void tpm_tis_class_init(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>  
>      dc->realize = tpm_tis_realizefn;
> +    dc->unrealize = tpm_tis_unrealizefn;
>      dc->props = tpm_tis_properties;
>      dc->reset = tpm_tis_reset;
>      dc->vmsd  = &vmstate_tpm_tis;
>

Patch

diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index d4d8152..303d778 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -881,24 +881,29 @@  static void tpm_tis_realizefn(DeviceState *dev, Error **errp)
     tis->bh = qemu_bh_new(tpm_tis_receive_bh, s);
 
     isa_init_irq(&s->busdev, &tis->irq, tis->irq_num);
+    memory_region_add_subregion(isa_address_space(&s->busdev), TPM_TIS_ADDR_BASE,
+                                &s->mmio);
+}
+
+static void tpm_tis_unrealizefn(DeviceState *dev, Error **errp)
+{
+    TPMState *s = TPM(dev);
+
+    memory_region_del_subregion(get_system_memory(), &s->mmio);
 }
 
 static void tpm_tis_initfn(Object *obj)
 {
-    ISADevice *dev = ISA_DEVICE(obj);
     TPMState *s = TPM(obj);
 
     memory_region_init_io(&s->mmio, &tpm_tis_memory_ops, s, "tpm-tis-mmio",
                           TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT);
-    memory_region_add_subregion(isa_address_space(dev), TPM_TIS_ADDR_BASE,
-                                &s->mmio);
 }
 
 static void tpm_tis_uninitfn(Object *obj)
 {
     TPMState *s = TPM(obj);
 
-    memory_region_del_subregion(get_system_memory(), &s->mmio);
     memory_region_destroy(&s->mmio);
 }
 
@@ -907,6 +912,7 @@  static void tpm_tis_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->realize = tpm_tis_realizefn;
+    dc->unrealize = tpm_tis_unrealizefn;
     dc->props = tpm_tis_properties;
     dc->reset = tpm_tis_reset;
     dc->vmsd  = &vmstate_tpm_tis;