From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Igor Mammedov <imammedo@redhat.com>,
Anthony Liguori <aliguori@amazon.com>
Subject: [Qemu-devel] [PULL 21/29] acpi: factor out common cpu hotplug code for PIIX4/Q35
Date: Mon, 20 Jan 2014 16:10:35 +0200 [thread overview]
Message-ID: <1390226872-781-22-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1390226872-781-1-git-send-email-mst@redhat.com>
From: Igor Mammedov <imammedo@redhat.com>
.. so it could be used for adding CPU hotplug to Q35 machine
Add an additional header with that will be shared between
C and ASL code: include/hw/acpi/cpu_hotplug_defs.h
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/acpi/cpu_hotplug.h | 27 +++++++++++++
include/hw/acpi/cpu_hotplug_defs.h | 22 +++++++++++
hw/acpi/cpu_hotplug.c | 64 +++++++++++++++++++++++++++++++
hw/acpi/piix4.c | 77 +++-----------------------------------
hw/acpi/Makefile.objs | 2 +-
5 files changed, 120 insertions(+), 72 deletions(-)
create mode 100644 include/hw/acpi/cpu_hotplug.h
create mode 100644 include/hw/acpi/cpu_hotplug_defs.h
create mode 100644 hw/acpi/cpu_hotplug.c
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
new file mode 100644
index 0000000..4576400
--- /dev/null
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -0,0 +1,27 @@
+/*
+ * QEMU ACPI hotplug utilities
+ *
+ * Copyright (C) 2013 Red Hat Inc
+ *
+ * Authors:
+ * Igor Mammedov <imammedo@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef ACPI_HOTPLUG_H
+#define ACPI_HOTPLUG_H
+
+#include "hw/acpi/acpi.h"
+#include "hw/acpi/cpu_hotplug_defs.h"
+
+typedef struct AcpiCpuHotplug {
+ MemoryRegion io;
+ uint8_t sts[ACPI_GPE_PROC_LEN];
+} AcpiCpuHotplug;
+
+void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu);
+
+void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
+ AcpiCpuHotplug *gpe_cpu, uint16_t base);
+#endif
diff --git a/include/hw/acpi/cpu_hotplug_defs.h b/include/hw/acpi/cpu_hotplug_defs.h
new file mode 100644
index 0000000..c6c4f78
--- /dev/null
+++ b/include/hw/acpi/cpu_hotplug_defs.h
@@ -0,0 +1,22 @@
+/*
+ * QEMU ACPI hotplug utilities shared defines
+ *
+ * Copyright (C) 2013 Red Hat Inc
+ *
+ * Authors:
+ * Igor Mammedov <imammedo@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef ACPI_HOTPLUG_DEFS_H
+#define ACPI_HOTPLUG_DEFS_H
+
+/*
+ * ONLY DEFINEs are permited in this file since it's shared
+ * between C and ASL code.
+ */
+#define ACPI_CPU_HOTPLUG_STATUS 4
+#define ACPI_GPE_PROC_LEN 32
+
+#endif
diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
new file mode 100644
index 0000000..48928dc
--- /dev/null
+++ b/hw/acpi/cpu_hotplug.c
@@ -0,0 +1,64 @@
+/*
+ * QEMU ACPI hotplug utilities
+ *
+ * Copyright (C) 2013 Red Hat Inc
+ *
+ * Authors:
+ * Igor Mammedov <imammedo@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include "hw/hw.h"
+#include "hw/acpi/cpu_hotplug.h"
+
+static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
+{
+ AcpiCpuHotplug *cpus = opaque;
+ uint64_t val = cpus->sts[addr];
+
+ return val;
+}
+
+static void cpu_status_write(void *opaque, hwaddr addr, uint64_t data,
+ unsigned int size)
+{
+ /* TODO: implement VCPU removal on guest signal that CPU can be removed */
+}
+
+static const MemoryRegionOps AcpiCpuHotplug_ops = {
+ .read = cpu_status_read,
+ .write = cpu_status_write,
+ .endianness = DEVICE_LITTLE_ENDIAN,
+ .valid = {
+ .min_access_size = 1,
+ .max_access_size = 1,
+ },
+};
+
+void AcpiCpuHotplug_add(ACPIGPE *gpe, AcpiCpuHotplug *g, CPUState *cpu)
+{
+ CPUClass *k = CPU_GET_CLASS(cpu);
+ int64_t cpu_id;
+
+ *gpe->sts = *gpe->sts | ACPI_CPU_HOTPLUG_STATUS;
+ cpu_id = k->get_arch_id(CPU(cpu));
+ g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
+}
+
+void AcpiCpuHotplug_init(MemoryRegion *parent, Object *owner,
+ AcpiCpuHotplug *gpe_cpu, uint16_t base)
+{
+ CPUState *cpu;
+
+ CPU_FOREACH(cpu) {
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+ int64_t id = cc->get_arch_id(cpu);
+
+ g_assert((id / 8) < ACPI_GPE_PROC_LEN);
+ gpe_cpu->sts[id / 8] |= (1 << (id % 8));
+ }
+ memory_region_init_io(&gpe_cpu->io, owner, &AcpiCpuHotplug_ops,
+ gpe_cpu, "acpi-cpu-hotplug", ACPI_GPE_PROC_LEN);
+ memory_region_add_subregion(parent, base, &gpe_cpu->io);
+}
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 1aa35bc..12f8dde 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -31,6 +31,7 @@
#include "exec/address-spaces.h"
#include "hw/acpi/piix4.h"
#include "hw/acpi/pcihp.h"
+#include "hw/acpi/cpu_hotplug.h"
//#define DEBUG
@@ -51,20 +52,14 @@
#define PCI_RMV_BASE 0xae0c
#define PIIX4_PROC_BASE 0xaf00
-#define PIIX4_PROC_LEN 32
#define PIIX4_PCI_HOTPLUG_STATUS 2
-#define PIIX4_CPU_HOTPLUG_STATUS 4
struct pci_status {
uint32_t up; /* deprecated, maintained for migration compatibility */
uint32_t down;
};
-typedef struct CPUStatus {
- uint8_t sts[PIIX4_PROC_LEN];
-} CPUStatus;
-
typedef struct PIIX4PMState {
/*< private >*/
PCIDevice parent_obj;
@@ -74,7 +69,6 @@ typedef struct PIIX4PMState {
uint32_t io_base;
MemoryRegion io_gpe;
- MemoryRegion io_cpu;
ACPIREGS ar;
APMState apm;
@@ -102,7 +96,7 @@ typedef struct PIIX4PMState {
uint8_t disable_s4;
uint8_t s4_val;
- CPUStatus gpe_cpu;
+ AcpiCpuHotplug gpe_cpu;
Notifier cpu_added_notifier;
} PIIX4PMState;
@@ -683,61 +677,13 @@ static const MemoryRegionOps piix4_pci_ops = {
},
};
-static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
-{
- PIIX4PMState *s = opaque;
- CPUStatus *cpus = &s->gpe_cpu;
- uint64_t val = cpus->sts[addr];
-
- return val;
-}
-
-static void cpu_status_write(void *opaque, hwaddr addr, uint64_t data,
- unsigned int size)
-{
- /* TODO: implement VCPU removal on guest signal that CPU can be removed */
-}
-
-static const MemoryRegionOps cpu_hotplug_ops = {
- .read = cpu_status_read,
- .write = cpu_status_write,
- .endianness = DEVICE_LITTLE_ENDIAN,
- .valid = {
- .min_access_size = 1,
- .max_access_size = 1,
- },
-};
-
-typedef enum {
- PLUG,
- UNPLUG,
-} HotplugEventType;
-
-static void piix4_cpu_hotplug_req(PIIX4PMState *s, CPUState *cpu,
- HotplugEventType action)
-{
- CPUStatus *g = &s->gpe_cpu;
- ACPIGPE *gpe = &s->ar.gpe;
- CPUClass *k = CPU_GET_CLASS(cpu);
- int64_t cpu_id;
-
- assert(s != NULL);
-
- *gpe->sts = *gpe->sts | PIIX4_CPU_HOTPLUG_STATUS;
- cpu_id = k->get_arch_id(CPU(cpu));
- if (action == PLUG) {
- g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
- } else {
- g->sts[cpu_id / 8] &= ~(1 << (cpu_id % 8));
- }
- acpi_update_sci(&s->ar, s->irq);
-}
-
static void piix4_cpu_added_req(Notifier *n, void *opaque)
{
PIIX4PMState *s = container_of(n, PIIX4PMState, cpu_added_notifier);
- piix4_cpu_hotplug_req(s, CPU(opaque), PLUG);
+ assert(s != NULL);
+ AcpiCpuHotplug_add(&s->ar.gpe, &s->gpe_cpu, CPU(opaque));
+ acpi_update_sci(&s->ar, s->irq);
}
static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
@@ -746,8 +692,6 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
PCIBus *bus, PIIX4PMState *s)
{
- CPUState *cpu;
-
memory_region_init_io(&s->io_gpe, OBJECT(s), &piix4_gpe_ops, s,
"acpi-gpe0", GPE_LEN);
memory_region_add_subregion(parent, GPE_BASE, &s->io_gpe);
@@ -762,16 +706,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
pci_bus_hotplug(bus, piix4_device_hotplug, DEVICE(s));
}
- CPU_FOREACH(cpu) {
- CPUClass *cc = CPU_GET_CLASS(cpu);
- int64_t id = cc->get_arch_id(cpu);
-
- g_assert((id / 8) < PIIX4_PROC_LEN);
- s->gpe_cpu.sts[id / 8] |= (1 << (id % 8));
- }
- memory_region_init_io(&s->io_cpu, OBJECT(s), &cpu_hotplug_ops, s,
- "acpi-cpu-hotplug", PIIX4_PROC_LEN);
- memory_region_add_subregion(parent, PIIX4_PROC_BASE, &s->io_cpu);
+ AcpiCpuHotplug_init(parent, OBJECT(s), &s->gpe_cpu, PIIX4_PROC_BASE);
s->cpu_added_notifier.notify = piix4_cpu_added_req;
qemu_register_cpu_added_notifier(&s->cpu_added_notifier);
}
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index 841eca2..397d32b 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -1 +1 @@
-common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o
+common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
--
MST
next prev parent reply other threads:[~2014-01-20 14:09 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-20 14:09 [Qemu-devel] [PULL 00/29] acpi, pci, pc, virtio fixes and enhancements Michael S. Tsirkin
2014-01-20 14:09 ` [Qemu-devel] [PULL 01/29] Python-lang gdb script to extract x86_64 guest vmcore from qemu coredump Michael S. Tsirkin
2014-01-20 14:09 ` [Qemu-devel] [PULL 02/29] Add DSDT node for AppleSMC Michael S. Tsirkin
2014-01-20 14:09 ` [Qemu-devel] [PULL 03/29] ACPI: Fix AppleSMC _STA size Michael S. Tsirkin
2014-01-20 14:09 ` [Qemu-devel] [PULL 04/29] virtio: Fix return value for dummy function vhost_net_virtqueue_pending Michael S. Tsirkin
2014-01-20 14:09 ` [Qemu-devel] [PULL 05/29] acpi unit-test: add test files Michael S. Tsirkin
2014-01-20 14:09 ` [Qemu-devel] [PULL 06/29] configure: added acpi unit-test files Michael S. Tsirkin
2014-01-20 14:09 ` [Qemu-devel] [PULL 07/29] acpi unit-test: compare DSDT and SSDT tables against expected values Michael S. Tsirkin
2014-01-20 14:09 ` [Qemu-devel] [PULL 08/29] configure: add CONFIG_IASL to config-host.h Michael S. Tsirkin
2014-01-20 14:09 ` [Qemu-devel] [PULL 09/29] acpi unit-test: extract iasl executable from configuration Michael S. Tsirkin
2014-01-20 14:09 ` [Qemu-devel] [PULL 10/29] acpi unit-test: added script to rebuild the expected aml files Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 11/29] acpi unit-test: hook to rebuild " Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 12/29] tests: fix acpi to work on bigendian host Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 13/29] acpi unit-test: renamed ssdt_tables to tables Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 14/29] acpi unit-test: resolved iasl crash Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 15/29] acpi unit-test: do not fail on asl mismatch Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 16/29] pc: make: fix dependencies: rebuild when included file is changed Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 17/29] pci: add pci_for_each_bus_depth_first Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 18/29] pcihp: generalization of piix4 acpi Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 19/29] piix4: add acpi pci hotplug support Michael S. Tsirkin
2014-01-20 16:16 ` Michael S. Tsirkin
2014-01-20 16:31 ` Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 20/29] acpi-build: enable hotplug for PCI bridges Michael S. Tsirkin
2014-01-20 14:10 ` Michael S. Tsirkin [this message]
2014-01-20 14:10 ` [Qemu-devel] [PULL 22/29] acpi: ich9: add CPU hotplug handling to Q35 machine Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 23/29] pc: set PRST base in DSDT depending on chipset Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 24/29] pc: PIIX DSDT: exclude CPU/PCI hotplug & GPE0 IO range from PCI bus resources Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 25/29] pc: Q35 DSDT: exclude CPU hotplug " Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 26/29] pc: ACPI: expose PRST IO range via _CRS Michael S. Tsirkin
2014-01-20 14:10 ` [Qemu-devel] [PULL 27/29] pc: ACPI: unify source of CPU hotplug IO base/len Michael S. Tsirkin
2014-01-20 14:11 ` [Qemu-devel] [PULL 28/29] pc: ACPI: update acpi-dsdt.hex.generated q35-acpi-dsdt.hex.generated Michael S. Tsirkin
2014-01-20 14:11 ` [Qemu-devel] [PULL 29/29] acpi-test: update expected AML since recent changes Michael S. Tsirkin
2014-01-26 9:47 ` [Qemu-devel] [PULL 00/29] acpi, pci, pc, virtio fixes and enhancements Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1390226872-781-22-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=aliguori@amazon.com \
--cc=imammedo@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).