From patchwork Thu Apr 12 09:19:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10338073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 72D7960329 for ; Thu, 12 Apr 2018 09:21:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AD832875E for ; Thu, 12 Apr 2018 09:21:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F9EB28754; Thu, 12 Apr 2018 09:21:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C74F328757 for ; Thu, 12 Apr 2018 09:21:04 +0000 (UTC) Received: from localhost ([::1]:50887 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6YPf-00041a-Fn for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 Apr 2018 05:21:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6YOZ-0002tz-Ic for qemu-devel@nongnu.org; Thu, 12 Apr 2018 05:19:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6YOV-00077k-GR for qemu-devel@nongnu.org; Thu, 12 Apr 2018 05:19:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38486 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f6YOV-00077P-B1; Thu, 12 Apr 2018 05:19:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EE4180D30F3; Thu, 12 Apr 2018 09:19:49 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-194.ams2.redhat.com [10.36.117.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBA8E215CDC6; Thu, 12 Apr 2018 09:19:47 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 12 Apr 2018 11:19:35 +0200 Message-Id: <20180412091936.32446-3-david@redhat.com> In-Reply-To: <20180412091936.32446-1-david@redhat.com> References: <20180412091936.32446-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 12 Apr 2018 09:19:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 12 Apr 2018 09:19:49 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v1 2/3] machine: make MemoryHotplugState accessible via the machine X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , "Markus Armbruster --cc=qemu-ppc @ nongnu . org" , qemu-s390x@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Let's allow to query the MemoryHotplugState from the machine. This allows us to generically detect if a certain machine has support for memory devices, and to generically manage it (find free address range, plug/unplug a memory region). Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 12 ++++++++++++ hw/ppc/spapr.c | 12 ++++++++++++ include/hw/boards.h | 16 ++++++++++++++++ include/hw/mem/pc-dimm.h | 12 +----------- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index d36bac8c89..fa8862af33 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2337,6 +2337,17 @@ static void x86_nmi(NMIState *n, int cpu_index, Error **errp) } } +static MemoryHotplugState *pc_machine_get_memory_hotplug_state(MachineState *ms) +{ + PCMachineState *pcms = PC_MACHINE(ms); + + if (!pcms->hotplug_memory.base) { + /* hotplug not supported */ + return NULL; + } + return &pcms->hotplug_memory; +} + static void pc_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -2376,6 +2387,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) hc->unplug = pc_machine_device_unplug_cb; nc->nmi_monitor_handler = x86_nmi; mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE; + mc->get_memory_hotplug_state = pc_machine_get_memory_hotplug_state; object_class_property_add(oc, PC_MACHINE_MEMHP_REGION_SIZE, "int", pc_machine_get_hotplug_memory_region_size, NULL, diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index ea93c5de08..0a6528a421 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3867,6 +3867,17 @@ PowerPCCPU *spapr_find_cpu(int vcpu_id) return NULL; } +static MemoryHotplugState *spapr_get_memory_hotplug_state(MachineState *ms) +{ + sPAPRMachineState *spapr = SPAPR_MACHINE(machine); + + if (!spapr->hotplug_memory.base) { + /* hotplug not supported */ + return NULL; + } + return &spapr->hotplug_memory; +} + static void spapr_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -3926,6 +3937,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) * in which LMBs are represented and hot-added */ mc->numa_mem_align_shift = 28; + mc->get_memory_hotplug_state = spapr_get_memory_hotplug_state; smc->default_caps.caps[SPAPR_CAP_HTM] = SPAPR_CAP_OFF; smc->default_caps.caps[SPAPR_CAP_VSX] = SPAPR_CAP_ON; diff --git a/include/hw/boards.h b/include/hw/boards.h index a609239112..447bdc7219 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -105,6 +105,17 @@ typedef struct { CPUArchId cpus[0]; } CPUArchIdList; +/** + * MemoryHotplugState: + * @base: address in guest physical address space where hotplug memory + * address space begins. + * @mr: hotplug memory address space container + */ +typedef struct MemoryHotplugState { + hwaddr base; + MemoryRegion mr; +} MemoryHotplugState; + /** * MachineClass: * @max_cpus: maximum number of CPUs supported. Default: 1 @@ -156,6 +167,10 @@ typedef struct { * should instead use "unimplemented-device" for all memory ranges where * the guest will attempt to probe for a device that QEMU doesn't * implement and a stub device is required. + * @get_memory_hotplug_state: + * If a machine support memory hotplug, the returned data ontains + * information about the portion of guest physical address space + * where memory devices can be mapped to (e.g. to hotplug a pc-dimm). */ struct MachineClass { /*< private >*/ @@ -212,6 +227,7 @@ struct MachineClass { unsigned cpu_index); const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine); int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx); + MemoryHotplugState *(*get_memory_hotplug_state)(MachineState *ms); }; /** diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index e88073321f..8bda37adab 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -19,6 +19,7 @@ #include "exec/memory.h" #include "sysemu/hostmem.h" #include "hw/qdev.h" +#include "hw/boards.h" #define TYPE_PC_DIMM "pc-dimm" #define PC_DIMM(obj) \ @@ -75,17 +76,6 @@ typedef struct PCDIMMDeviceClass { MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm); } PCDIMMDeviceClass; -/** - * MemoryHotplugState: - * @base: address in guest physical address space where hotplug memory - * address space begins. - * @mr: hotplug memory address space container - */ -typedef struct MemoryHotplugState { - hwaddr base; - MemoryRegion mr; -} MemoryHotplugState; - uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, uint64_t address_space_size, uint64_t *hint, uint64_t align, uint64_t size,