From patchwork Thu Aug 28 03:36:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gu Zheng X-Patchwork-Id: 383675 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 398FE140170 for ; Thu, 28 Aug 2014 14:00:52 +1000 (EST) Received: from localhost ([::1]:34367 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMqtF-0006HS-U9 for incoming@patchwork.ozlabs.org; Thu, 28 Aug 2014 00:00:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMqsc-0005Tn-Cj for qemu-devel@nongnu.org; Thu, 28 Aug 2014 00:00:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XMqsW-0004SV-If for qemu-devel@nongnu.org; Thu, 28 Aug 2014 00:00:10 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:34738) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMqsW-0004Oe-4h for qemu-devel@nongnu.org; Thu, 28 Aug 2014 00:00:04 -0400 Received: from kw-mxoi1.gw.nic.fujitsu.com (unknown [10.0.237.133]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id DBFB83EE0C5 for ; Thu, 28 Aug 2014 13:00:02 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by kw-mxoi1.gw.nic.fujitsu.com (Postfix) with ESMTP id 76C20AC0847 for ; Thu, 28 Aug 2014 13:00:01 +0900 (JST) Received: from s00.gw.fujitsu.co.jp (s00.gw.nic.fujitsu.com [133.161.11.15]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 1F3F41DB8032 for ; Thu, 28 Aug 2014 13:00:01 +0900 (JST) Received: from s00.gw.fujitsu.co.jp (kw-mxio2.gw.nic.fujitsu.com [10.0.237.142]) by s00.gw.fujitsu.co.jp (Postfix) with ESMTP id F2EB01180D2; Thu, 28 Aug 2014 13:00:00 +0900 (JST) Received: from guz (unknown [10.167.226.100]) by s00.gw.fujitsu.co.jp (Postfix) with ESMTP id BD8C18A001; Thu, 28 Aug 2014 13:00:00 +0900 (JST) Received: (from root@localhost) by guz (8.14.5/8.14.5/Submit) id s7S3ixTS009689; Thu, 28 Aug 2014 11:44:59 +0800 From: Gu Zheng To: qemu-devel@nongnu.org, imammedo@redhat.com, afaerber@suse.de Date: Thu, 28 Aug 2014 11:36:39 +0800 Message-Id: <1409197002-9498-8-git-send-email-guz.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1409197002-9498-1-git-send-email-guz.fnst@cn.fujitsu.com> References: <1409197002-9498-1-git-send-email-guz.fnst@cn.fujitsu.com> X-TM-AS-MML: No X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 192.51.44.36 Cc: chen.fan.fnst@cn.fujitsu.com, anshul.makkar@profitbricks.com, isimatu.yasuaki@jp.fujitsu.com, Gu Zheng , tangchen@cn.fujitsu.com Subject: [Qemu-devel] [RFC V2 07/10] qom cpu: add UNPLUG cpu notify support 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 Introduce a common cpu hotplug notifier(CPUNotifier) to support UNPLUG cpu notify. Signed-off-by: Gu Zheng Signed-off-by: Chen Fan --- hw/acpi/cpu_hotplug.c | 15 +++++++++++---- hw/acpi/ich9.c | 5 ++++- hw/acpi/piix4.c | 11 +++++++---- include/hw/acpi/cpu_hotplug.h | 13 ++++++++++++- qom/cpu.c | 7 ++++++- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c index 2ad83a0..56cb316 100644 --- a/hw/acpi/cpu_hotplug.c +++ b/hw/acpi/cpu_hotplug.c @@ -36,15 +36,22 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = { }, }; -void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu) +void AcpiCpuHotplug_handle(ACPIGPE *gpe, AcpiCpuHotplug *g, + CPUNotifier *notify) { - CPUClass *k = CPU_GET_CLASS(cpu); + CPUClass *k = CPU_GET_CLASS(notify->dev); + HotplugEventType type = notify->type; int64_t cpu_id; *gpe->sts = *gpe->sts | ACPI_CPU_HOTPLUG_STATUS; - cpu_id = k->get_arch_id(CPU(cpu)); + cpu_id = k->get_arch_id(CPU(notify->dev)); g_assert((cpu_id / 8) < ACPI_GPE_PROC_LEN); - g->sts[cpu_id / 8] |= (1 << (cpu_id % 8)); + + if (type == PLUG) { + g->sts[cpu_id / 8] |= (1 << (cpu_id % 8)); + } else { + g->sts[cpu_id / 8] &= ~(1 << (cpu_id % 8)); + } } void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner, diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c index 804f774..2db491d 100644 --- a/hw/acpi/ich9.c +++ b/hw/acpi/ich9.c @@ -212,9 +212,12 @@ static void pm_powerdown_req(Notifier *n, void *opaque) static void ich9_cpu_hotplug_req(Notifier *n, void *opaque) { ICH9LPCPMRegs *pm = container_of(n, ICH9LPCPMRegs, cpu_hotplug_notifier); + CPUNotifier *notifier = (CPUNotifier *)opaque; assert(pm != NULL); - AcpiCpuHotplug_add(&pm->acpi_regs.gpe, &pm->gpe_cpu, CPU(opaque)); + + AcpiCpuHotplug_handle(&pm->acpi_regs.gpe, &pm->gpe_cpu, notifier); + acpi_update_sci(&pm->acpi_regs, pm->irq); } diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 5cd6300..cc15b60 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -93,7 +93,7 @@ typedef struct PIIX4PMState { #define PIIX4_PM(obj) \ OBJECT_CHECK(PIIX4PMState, (obj), TYPE_PIIX4_PM) -static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, +static void piix4_acpi_system_hotplug_init(MemoryRegion *parent, PCIBus *bus, PIIX4PMState *s); #define ACPI_ENABLE 0xf1 @@ -465,7 +465,7 @@ static int piix4_pm_initfn(PCIDevice *dev) qemu_add_machine_init_done_notifier(&s->machine_ready); qemu_register_reset(piix4_reset, s); - piix4_acpi_system_hot_add_init(pci_address_space_io(dev), dev->bus, s); + piix4_acpi_system_hotplug_init(pci_address_space_io(dev), dev->bus, s); piix4_pm_add_propeties(s); return 0; @@ -547,13 +547,16 @@ static const MemoryRegionOps piix4_gpe_ops = { static void piix4_cpu_hotplug(Notifier *n, void *opaque) { PIIX4PMState *s = container_of(n, PIIX4PMState, cpu_hotplug_notifier); + CPUNotifier *notifier = (CPUNotifier *)opaque; assert(s != NULL); - AcpiCpuHotplug_add(&s->ar.gpe, &s->gpe_cpu, CPU(opaque)); + + AcpiCpuHotplug_handle(&s->ar.gpe, &s->gpe_cpu, notifier); + acpi_update_sci(&s->ar, s->irq); } -static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, +static void piix4_acpi_system_hotplug_init(MemoryRegion *parent, PCIBus *bus, PIIX4PMState *s) { memory_region_init_io(&s->io_gpe, OBJECT(s), &piix4_gpe_ops, s, diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h index 9e5d30c..4fe0066 100644 --- a/include/hw/acpi/cpu_hotplug.h +++ b/include/hw/acpi/cpu_hotplug.h @@ -15,12 +15,23 @@ #include "hw/acpi/acpi.h" #include "hw/acpi/pc-hotplug.h" +typedef enum { + PLUG, + UNPLUG, +} HotplugEventType; + +typedef struct CPUNotifier { + DeviceState *dev; + HotplugEventType type; +} CPUNotifier; + typedef struct AcpiCpuHotplug { MemoryRegion io; uint8_t sts[ACPI_GPE_PROC_LEN]; } AcpiCpuHotplug; -void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu); +void AcpiCpuHotplug_handle(ACPIGPE *gpe, AcpiCpuHotplug *g, + CPUNotifier *notify); void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner, AcpiCpuHotplug *gpe_cpu, uint16_t base); diff --git a/qom/cpu.c b/qom/cpu.c index add92b1..f921282 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -25,6 +25,7 @@ #include "qemu/log.h" #include "qemu/error-report.h" #include "sysemu/sysemu.h" +#include "hw/acpi/cpu_hotplug.h" bool cpu_exists(int64_t id) { @@ -304,8 +305,12 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) cpu_vmstate_register(cpu); if (dev->hotplugged) { + CPUNotifier notifier; + + notifier.dev = dev; + notifier.type = PLUG; cpu_synchronize_post_init(cpu); - notifier_list_notify(&cpu_hotplug_notifiers, dev); + notifier_list_notify(&cpu_hotplug_notifiers, ¬ifier); cpu_resume(cpu); } }