From patchwork Tue Sep 10 09:43:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenfan X-Patchwork-Id: 273806 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4FF0E2C00EB for ; Tue, 10 Sep 2013 19:46:39 +1000 (EST) Received: from localhost ([::1]:56683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKWr-0000Mq-Eg for incoming@patchwork.ozlabs.org; Tue, 10 Sep 2013 05:46:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKWL-0000JI-H7 for qemu-devel@nongnu.org; Tue, 10 Sep 2013 05:46:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJKWG-0006lx-Hc for qemu-devel@nongnu.org; Tue, 10 Sep 2013 05:46:05 -0400 Received: from [222.73.24.84] (port=64787 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKWF-0006ii-HQ for qemu-devel@nongnu.org; Tue, 10 Sep 2013 05:46:00 -0400 X-IronPort-AV: E=Sophos;i="4.90,877,1371052800"; d="scan'208";a="8473929" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 10 Sep 2013 17:42:39 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r8A9jlrS024413; Tue, 10 Sep 2013 17:45:47 +0800 Received: from G08FNSTD131468.fnst.cn.fujitsu.com ([10.167.226.78]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013091017432879-1376618 ; Tue, 10 Sep 2013 17:43:28 +0800 From: Chen Fan To: qemu-devel@nongnu.org Date: Tue, 10 Sep 2013 17:43:42 +0800 Message-Id: X-Mailer: git-send-email 1.8.1.4 In-Reply-To: References: X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/09/10 17:43:28, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/09/10 17:43:30, Serialize complete at 2013/09/10 17:43:30 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [RFC qom-cpu v2 2/8] x86: add x86_cpu_unrealizefn() for cpu apic remove X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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(+) 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;