qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <richardw.yang@linux.intel.com>
To: qemu-devel@nongnu.org
Cc: mst@redhat.com, marcel.apfelbaum@gmail.com, imammedo@redhat.com,
	Wei Yang <richardw.yang@linux.intel.com>
Subject: [Qemu-devel] [PATCH] i386, acpi: check acpi_memory_hotplug capacity in pre_plug
Date: Thu, 14 Feb 2019 08:52:25 +0800	[thread overview]
Message-ID: <20190214005225.24048-1-richardw.yang@linux.intel.com> (raw)

Currently we do device realization like below:

   hotplug_handler_pre_plug()
   dc->realize()
   hotplug_handler_plug()

Before we do device realization and plug, we would allocate necessary
resources and check the capacity.

While we leave acpi_memory_hotplug capacity check in the last step. This
looks not comply with current architecture and does some unnecessary
work.

This patch abstract the check on acpi_memory_hotplug capacity in
pre_plug stage.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
---
 hw/acpi/piix4.c | 14 ++++++++++++--
 hw/i386/pc.c    |  8 ++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index e330f24c71..c97b747496 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -370,13 +370,22 @@ static void piix4_pm_powerdown_req(Notifier *n, void *opaque)
     acpi_pm1_evt_power_down(&s->ar);
 }
 
+static void piix4_device_pre_plug_cb(HotplugHandler *hotplug_dev,
+                                 DeviceState *dev, Error **errp)
+{
+    PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) &&
+        !s->acpi_memory_hotplug.is_enabled)
+        error_setg(errp,
+            "memory hotplug is not enabled: PIIX4 memory hotplug disabled");
+}
 static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
                                  DeviceState *dev, Error **errp)
 {
     PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-    if (s->acpi_memory_hotplug.is_enabled &&
-        object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
             nvdimm_acpi_plug_cb(hotplug_dev, dev);
         } else {
@@ -702,6 +711,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
      */
     dc->user_creatable = false;
     dc->hotpluggable = false;
+    hc->pre_plug = piix4_device_pre_plug_cb;
     hc->plug = piix4_device_plug_cb;
     hc->unplug_request = piix4_device_unplug_request_cb;
     hc->unplug = piix4_device_unplug_cb;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 734d3268fa..3c6eed0cd3 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1662,6 +1662,7 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
     const PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     const bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM);
     const uint64_t legacy_align = TARGET_PAGE_SIZE;
+    HotplugHandlerClass *hhc;
 
     /*
      * When -no-acpi is used with Q35 machine type, no ACPI is built,
@@ -1674,6 +1675,13 @@ static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
         return;
     }
 
+    /*
+     * Check acpi_dev memory hotplug capacity
+     */
+    hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev);
+    if (hcc->pre_plug)
+        hhc->pre_plug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, errp);
+
     if (is_nvdimm && !pcms->acpi_nvdimm_state.is_enabled) {
         error_setg(errp, "nvdimm is not enabled: missing 'nvdimm' in '-M'");
         return;
-- 
2.19.1

             reply	other threads:[~2019-02-14  0:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-14  0:52 Wei Yang [this message]
2019-02-14 11:25 ` [Qemu-devel] [PATCH] i386, acpi: check acpi_memory_hotplug capacity in pre_plug Igor Mammedov
2019-02-14 20:53   ` Wei Yang
2019-02-15 11:14     ` Igor Mammedov
2019-02-16 21:54       ` Wei Yang

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=20190214005225.24048-1-richardw.yang@linux.intel.com \
    --to=richardw.yang@linux.intel.com \
    --cc=imammedo@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@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).