diff mbox

[RFC,qom-cpu,v2,2/8] x86: add x86_cpu_unrealizefn() for cpu apic remove

Message ID c80d40ea1465f12caca606a34452bffb035738ec.1378796990.git.chen.fan.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

chenfan Sept. 10, 2013, 9:43 a.m. UTC
Implement x86_cpu_unrealizefn() for corresponding x86_cpu_realizefn(),
which is mostly used to clear the apic related information at here.

Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
---
 hw/cpu/icc_bus.c                | 11 +++++++++++
 hw/i386/kvm/apic.c              |  6 ++++++
 hw/intc/apic.c                  |  7 +++++++
 hw/intc/apic_common.c           | 11 +++++++++++
 include/hw/cpu/icc_bus.h        |  1 +
 include/hw/i386/apic_internal.h |  1 +
 target-i386/cpu-qom.h           |  1 +
 target-i386/cpu.c               | 35 +++++++++++++++++++++++++++++++++++
 8 files changed, 73 insertions(+)

Comments

Andreas Färber Sept. 10, 2013, 12:26 p.m. UTC | #1
Am 10.09.2013 11:43, schrieb Chen Fan:
> Implement x86_cpu_unrealizefn() for corresponding x86_cpu_realizefn(),
> which is mostly used to clear the apic related information at here.
> 
> Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
> ---
>  hw/cpu/icc_bus.c                | 11 +++++++++++
>  hw/i386/kvm/apic.c              |  6 ++++++
>  hw/intc/apic.c                  |  7 +++++++
>  hw/intc/apic_common.c           | 11 +++++++++++
>  include/hw/cpu/icc_bus.h        |  1 +
>  include/hw/i386/apic_internal.h |  1 +
>  target-i386/cpu-qom.h           |  1 +
>  target-i386/cpu.c               | 35 +++++++++++++++++++++++++++++++++++
>  8 files changed, 73 insertions(+)

Some nitpicks below, mostly about adopting the latest concepts.

> diff --git a/hw/cpu/icc_bus.c b/hw/cpu/icc_bus.c
> index 8748cc5..45e87d1 100644
> --- a/hw/cpu/icc_bus.c
> +++ b/hw/cpu/icc_bus.c
> @@ -54,11 +54,22 @@ static void icc_device_realize(DeviceState *dev, Error **errp)
>      }
>  }
>  
> +static void icc_device_unrealize(DeviceState *dev, Error **errp)
> +{
> +    ICCDevice *id = ICC_DEVICE(dev);
> +    ICCDeviceClass *idc = ICC_DEVICE_GET_CLASS(id);
> +
> +    if (idc->exit) {
> +        idc->exit(id);

->unrealize

> +    }
> +}
> +
>  static void icc_device_class_init(ObjectClass *oc, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(oc);
>  
>      dc->realize = icc_device_realize;
> +    dc->unrealize = icc_device_unrealize;
>      dc->bus_type = TYPE_ICC_BUS;
>  }
>  
> diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c
> index 5609063..8f028a1 100644
> --- a/hw/i386/kvm/apic.c
> +++ b/hw/i386/kvm/apic.c
> @@ -181,11 +181,17 @@ static void kvm_apic_init(APICCommonState *s)
>      }
>  }
>  
> +static void kvm_apic_exit(APICCommonState *s)

kvm_apic_unrealize

> +{
> +    memory_region_destroy(&s->io_memory);
> +}
> +
>  static void kvm_apic_class_init(ObjectClass *klass, void *data)
>  {
>      APICCommonClass *k = APIC_COMMON_CLASS(klass);
>  
>      k->init = kvm_apic_init;
> +    k->exit = kvm_apic_exit;
>      k->set_base = kvm_apic_set_base;
>      k->set_tpr = kvm_apic_set_tpr;
>      k->get_tpr = kvm_apic_get_tpr;
> diff --git a/hw/intc/apic.c b/hw/intc/apic.c
> index a913186..23488b4 100644
> --- a/hw/intc/apic.c
> +++ b/hw/intc/apic.c
> @@ -882,11 +882,18 @@ static void apic_init(APICCommonState *s)
>      msi_supported = true;
>  }
>  
> +static void apic_uninit(APICCommonState *s)

apic_unrealize

> +{
> +    memory_region_destroy(&s->io_memory);
> +    local_apics[s->idx] = NULL;
> +}
> +
>  static void apic_class_init(ObjectClass *klass, void *data)
>  {
>      APICCommonClass *k = APIC_COMMON_CLASS(klass);
>  
>      k->init = apic_init;
> +    k->exit = apic_uninit;
>      k->set_base = apic_set_base;
>      k->set_tpr = apic_set_tpr;
>      k->get_tpr = apic_get_tpr;
> diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
> index 5568621..32c2f74 100644
> --- a/hw/intc/apic_common.c
> +++ b/hw/intc/apic_common.c
> @@ -316,6 +316,16 @@ static int apic_init_common(ICCDevice *dev)
>      return 0;
>  }
>  
> +static void apic_exit_common(ICCDevice *dev)
> +{
> +    APICCommonState *s = APIC_COMMON(dev);
> +    APICCommonClass *info;

acc please

> +
> +    info = APIC_COMMON_GET_CLASS(s);
> +    if (info->exit)
> +        info->exit(s);

Braces missing -> checkpatch.pl

> +}
> +
>  static void apic_dispatch_pre_save(void *opaque)
>  {
>      APICCommonState *s = APIC_COMMON(opaque);
> @@ -387,6 +397,7 @@ static void apic_common_class_init(ObjectClass *klass, void *data)
>      dc->no_user = 1;
>      dc->props = apic_properties_common;
>      idc->init = apic_init_common;
> +    idc->exit = apic_exit_common;
>  }
>  
>  static const TypeInfo apic_common_type = {
> diff --git a/include/hw/cpu/icc_bus.h b/include/hw/cpu/icc_bus.h
> index b550070..15d5374 100644
> --- a/include/hw/cpu/icc_bus.h
> +++ b/include/hw/cpu/icc_bus.h
> @@ -67,6 +67,7 @@ typedef struct ICCDeviceClass {
>      /*< public >*/
>  
>      int (*init)(ICCDevice *dev); /* TODO replace with QOM realize */
> +    void (*exit)(ICCDevice *dev);

DeviceUnrealize unrealize;

>  } ICCDeviceClass;
>  
>  #define TYPE_ICC_DEVICE "icc-device"
> diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
> index 1b0a7fb..87d5248 100644
> --- a/include/hw/i386/apic_internal.h
> +++ b/include/hw/i386/apic_internal.h
> @@ -81,6 +81,7 @@ typedef struct APICCommonClass
>      ICCDeviceClass parent_class;
>  
>      void (*init)(APICCommonState *s);
> +    void (*exit)(APICCommonState *s);

DeviceUnrealize unrealize;

>      void (*set_base)(APICCommonState *s, uint64_t val);
>      void (*set_tpr)(APICCommonState *s, uint8_t val);
>      uint8_t (*get_tpr)(APICCommonState *s);
> diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
> index c4447c2..1e520be 100644
> --- a/target-i386/cpu-qom.h
> +++ b/target-i386/cpu-qom.h
> @@ -50,6 +50,7 @@ typedef struct X86CPUClass {
>      /*< public >*/
>  
>      DeviceRealize parent_realize;
> +    DeviceUnrealize parent_unrealize;
>      void (*parent_reset)(CPUState *cpu);
>  } X86CPUClass;
>  
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 2b99683..6f9154d 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2339,10 +2339,31 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
>          return;
>      }
>  }
> +
> +static void x86_cpu_apic_unrealize(X86CPU *cpu, Error **errp)
> +{
> +    CPUX86State *env = &cpu->env;
> +    Error *local_err = NULL;
> +
> +    if (env->apic_state == NULL) {
> +        return;
> +    }
> +
> +    object_property_set_bool(OBJECT(env->apic_state), false, "realized", &local_err);
> +    if (local_err != NULL) {
> +        error_propagate(errp, local_err);
> +        return;
> +    }
> +
> +    qdev_free(env->apic_state);
> +}
>  #else
>  static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
>  {
>  }
> +static void x86_cpu_apic_unrealize(X86CPU *cpu, Error **errp)
> +{
> +}
>  #endif
>  
>  static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
> @@ -2418,6 +2439,18 @@ out:
>      }
>  }
>  
> +static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp)
> +{
> +    X86CPU *cpu = X86_CPU(dev);
> +    Error *local_err = NULL;
> +
> +    x86_cpu_apic_unrealize(cpu, &local_err);
> +    if (local_err != NULL) {
> +        error_propagate(errp, local_err);
> +        return;
> +    }
> +}
> +
>  /* Enables contiguous-apic-ID mode, for compatibility */
>  static bool compat_apic_id_mode;
>  
> @@ -2549,7 +2582,9 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
>      DeviceClass *dc = DEVICE_CLASS(oc);
>  
>      xcc->parent_realize = dc->realize;
> +    xcc->parent_unrealize = dc->unrealize;
>      dc->realize = x86_cpu_realizefn;
> +    dc->unrealize = x86_cpu_unrealizefn;
>      dc->bus_type = TYPE_ICC_BUS;
>      dc->props = x86_cpu_properties;
>  

Regards,
Andreas
diff mbox

Patch

diff --git a/hw/cpu/icc_bus.c b/hw/cpu/icc_bus.c
index 8748cc5..45e87d1 100644
--- a/hw/cpu/icc_bus.c
+++ b/hw/cpu/icc_bus.c
@@ -54,11 +54,22 @@  static void icc_device_realize(DeviceState *dev, Error **errp)
     }
 }
 
+static void icc_device_unrealize(DeviceState *dev, Error **errp)
+{
+    ICCDevice *id = ICC_DEVICE(dev);
+    ICCDeviceClass *idc = ICC_DEVICE_GET_CLASS(id);
+
+    if (idc->exit) {
+        idc->exit(id);
+    }
+}
+
 static void icc_device_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
 
     dc->realize = icc_device_realize;
+    dc->unrealize = icc_device_unrealize;
     dc->bus_type = TYPE_ICC_BUS;
 }
 
diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c
index 5609063..8f028a1 100644
--- a/hw/i386/kvm/apic.c
+++ b/hw/i386/kvm/apic.c
@@ -181,11 +181,17 @@  static void kvm_apic_init(APICCommonState *s)
     }
 }
 
+static void kvm_apic_exit(APICCommonState *s)
+{
+    memory_region_destroy(&s->io_memory);
+}
+
 static void kvm_apic_class_init(ObjectClass *klass, void *data)
 {
     APICCommonClass *k = APIC_COMMON_CLASS(klass);
 
     k->init = kvm_apic_init;
+    k->exit = kvm_apic_exit;
     k->set_base = kvm_apic_set_base;
     k->set_tpr = kvm_apic_set_tpr;
     k->get_tpr = kvm_apic_get_tpr;
diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index a913186..23488b4 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -882,11 +882,18 @@  static void apic_init(APICCommonState *s)
     msi_supported = true;
 }
 
+static void apic_uninit(APICCommonState *s)
+{
+    memory_region_destroy(&s->io_memory);
+    local_apics[s->idx] = NULL;
+}
+
 static void apic_class_init(ObjectClass *klass, void *data)
 {
     APICCommonClass *k = APIC_COMMON_CLASS(klass);
 
     k->init = apic_init;
+    k->exit = apic_uninit;
     k->set_base = apic_set_base;
     k->set_tpr = apic_set_tpr;
     k->get_tpr = apic_get_tpr;
diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index 5568621..32c2f74 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -316,6 +316,16 @@  static int apic_init_common(ICCDevice *dev)
     return 0;
 }
 
+static void apic_exit_common(ICCDevice *dev)
+{
+    APICCommonState *s = APIC_COMMON(dev);
+    APICCommonClass *info;
+
+    info = APIC_COMMON_GET_CLASS(s);
+    if (info->exit)
+        info->exit(s);
+}
+
 static void apic_dispatch_pre_save(void *opaque)
 {
     APICCommonState *s = APIC_COMMON(opaque);
@@ -387,6 +397,7 @@  static void apic_common_class_init(ObjectClass *klass, void *data)
     dc->no_user = 1;
     dc->props = apic_properties_common;
     idc->init = apic_init_common;
+    idc->exit = apic_exit_common;
 }
 
 static const TypeInfo apic_common_type = {
diff --git a/include/hw/cpu/icc_bus.h b/include/hw/cpu/icc_bus.h
index b550070..15d5374 100644
--- a/include/hw/cpu/icc_bus.h
+++ b/include/hw/cpu/icc_bus.h
@@ -67,6 +67,7 @@  typedef struct ICCDeviceClass {
     /*< public >*/
 
     int (*init)(ICCDevice *dev); /* TODO replace with QOM realize */
+    void (*exit)(ICCDevice *dev);
 } ICCDeviceClass;
 
 #define TYPE_ICC_DEVICE "icc-device"
diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
index 1b0a7fb..87d5248 100644
--- a/include/hw/i386/apic_internal.h
+++ b/include/hw/i386/apic_internal.h
@@ -81,6 +81,7 @@  typedef struct APICCommonClass
     ICCDeviceClass parent_class;
 
     void (*init)(APICCommonState *s);
+    void (*exit)(APICCommonState *s);
     void (*set_base)(APICCommonState *s, uint64_t val);
     void (*set_tpr)(APICCommonState *s, uint8_t val);
     uint8_t (*get_tpr)(APICCommonState *s);
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index c4447c2..1e520be 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -50,6 +50,7 @@  typedef struct X86CPUClass {
     /*< public >*/
 
     DeviceRealize parent_realize;
+    DeviceUnrealize parent_unrealize;
     void (*parent_reset)(CPUState *cpu);
 } X86CPUClass;
 
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 2b99683..6f9154d 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2339,10 +2339,31 @@  static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
         return;
     }
 }
+
+static void x86_cpu_apic_unrealize(X86CPU *cpu, Error **errp)
+{
+    CPUX86State *env = &cpu->env;
+    Error *local_err = NULL;
+
+    if (env->apic_state == NULL) {
+        return;
+    }
+
+    object_property_set_bool(OBJECT(env->apic_state), false, "realized", &local_err);
+    if (local_err != NULL) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    qdev_free(env->apic_state);
+}
 #else
 static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
 {
 }
+static void x86_cpu_apic_unrealize(X86CPU *cpu, Error **errp)
+{
+}
 #endif
 
 static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
@@ -2418,6 +2439,18 @@  out:
     }
 }
 
+static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp)
+{
+    X86CPU *cpu = X86_CPU(dev);
+    Error *local_err = NULL;
+
+    x86_cpu_apic_unrealize(cpu, &local_err);
+    if (local_err != NULL) {
+        error_propagate(errp, local_err);
+        return;
+    }
+}
+
 /* Enables contiguous-apic-ID mode, for compatibility */
 static bool compat_apic_id_mode;
 
@@ -2549,7 +2582,9 @@  static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     DeviceClass *dc = DEVICE_CLASS(oc);
 
     xcc->parent_realize = dc->realize;
+    xcc->parent_unrealize = dc->unrealize;
     dc->realize = x86_cpu_realizefn;
+    dc->unrealize = x86_cpu_unrealizefn;
     dc->bus_type = TYPE_ICC_BUS;
     dc->props = x86_cpu_properties;