From dd622978066d2cf29a26f246ad6c55f51a0a6272 Mon Sep 17 00:00:00 2001 From: Liu Jinsong <jinsong.liu@intel.com> Date: Wed, 21 Nov 2012 15:39:47 +0800 Subject: [PATCH 2/2] Xen acpi memory hotplug hypercall This patch implement Xen acpi memory hotplug hypercall, extracting memory information then hypercall to hypervisor. Signed-off-by: Liu Jinsong <jinsong.liu@intel.com> --- drivers/xen/xen-acpi-memhotplug.c | 44 +++++++++++++++++++++++++++++++++++++ include/xen/interface/platform.h | 9 +++++++ 2 files changed, 53 insertions(+), 0 deletions(-) diff --git a/drivers/xen/xen-acpi-memhotplug.c b/drivers/xen/xen-acpi-memhotplug.c index f0c7990..877f5c8 100644 --- a/drivers/xen/xen-acpi-memhotplug.c +++ b/drivers/xen/xen-acpi-memhotplug.c @@ -18,7 +18,10 @@ #include <linux/kernel.h> #include <linux/init.h> #include <linux/types.h> +#include <linux/acpi.h> #include <acpi/acpi_drivers.h> +#include <xen/interface/platform.h> +#include <asm/xen/hypercall.h> #define ACPI_MEMORY_DEVICE_CLASS "memory" #define ACPI_MEMORY_DEVICE_HID "PNP0C80" @@ -61,9 +64,50 @@ struct acpi_memory_device { static int acpi_hotmem_initialized; +static int xen_hotadd_memory(int pxm, struct acpi_memory_info *info) +{ + struct xen_platform_op op; + + op.cmd = XENPF_mem_hotadd; + op.u.mem_add.spfn = info->start_addr >> PAGE_SHIFT; + op.u.mem_add.epfn = (info->start_addr + info->length) >> PAGE_SHIFT; + op.u.mem_add.pxm = pxm; + + return HYPERVISOR_dom0_op(&op); +} int xen_acpi_memory_enable_device(struct acpi_memory_device *mem_device) { + int pxm, result; + int num_enabled = 0; + struct acpi_memory_info *info; + + if (!mem_device) + return -EINVAL; + + pxm = acpi_get_pxm(mem_device->device->handle); + if (pxm < 0) + return -EINVAL; + + list_for_each_entry(info, &mem_device->res_list, list) { + if (info->enabled) { /* just sanity check...*/ + num_enabled++; + continue; + } + + if (!info->length) + continue; + + result = xen_hotadd_memory(pxm, info); + if (result) + continue; + info->enabled = 1; + num_enabled++; + } + + if (!num_enabled) + return -EINVAL; + return 0; } diff --git a/include/xen/interface/platform.h b/include/xen/interface/platform.h index 4755b5f..45215d9 100644 --- a/include/xen/interface/platform.h +++ b/include/xen/interface/platform.h @@ -324,6 +324,14 @@ struct xenpf_cpu_ol { }; DEFINE_GUEST_HANDLE_STRUCT(xenpf_cpu_ol); +#define XENPF_mem_hotadd 59 +struct xenpf_mem_hotadd { + uint64_t spfn; + uint64_t epfn; + uint32_t pxm; + uint32_t flags; +}; + struct xen_platform_op { uint32_t cmd; uint32_t interface_version; /* XENPF_INTERFACE_VERSION */ @@ -341,6 +349,7 @@ struct xen_platform_op { struct xenpf_set_processor_pminfo set_pminfo; struct xenpf_pcpuinfo pcpu_info; struct xenpf_cpu_ol cpu_ol; + struct xenpf_mem_hotadd mem_add; uint8_t pad[128]; } u; }; -- 1.7.1