From 18a26e729b51ce1fe5c8355b86c9781ee551a8ce Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Tue, 2 Feb 2016 16:59:38 +0000 Subject: [PATCH] xen: use xendevicemodel_populate_ram Signed-off-by: Ian Campbell --- configure | 1 + include/hw/xen/xen_common.h | 21 +++++++++++++++++++++ xen-hvm.c | 19 ++++--------------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 3c272cfef..3872443d8 100755 --- a/configure +++ b/configure @@ -2184,6 +2184,7 @@ int main(void) { dm = xendevicemodel_open(NULL, 0, 0, NULL); xendevicemodel_shutdown(dm); xendevicemodel_set_pci_intx_level(dm, 0, 0, 0, 0, 0); + xendevicemodel_populate_ram(dm, 0, 0); return 0; } EOF diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index d8ddf8587..9522aea42 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -121,6 +121,27 @@ typedef xc_interface xendevicemodel_handle; #define xendevicemodel_s3_awaken(h) \ xc_set_hvm_param(h, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); +static inline int xendevicemodel_populate_ram(xendevicemodel_handle *h, + xen_pfn_t start_gpfn, + size_t nr_pfn) +{ + xen_pfn_t *pfn_list; + int i, ret; + + pfn_list = g_malloc(sizeof (*pfn_list) * nr_pfn); + + for (i = 0; i < nr_pfn; i++) { + pfn_list[i] = start_gpfn + i; + } + + ret = xc_domain_populate_physmap_exact(h, xen_domid, nr_pfn, + 0, 0, pfn_list); + + g_free(pfn_list); + + return ret; +} + #define xendevicemodel_set_pci_intx_level(h, d, b, dv, i, a) \ xc_hvm_set_pci_intx_level(h, xen_domid, b, d, dv, i, a) #define xendevicemodel_route_pci_intx_to_isa_irq(h, ix, ii) \ diff --git a/xen-hvm.c b/xen-hvm.c index c090c5e75..ff73fe87a 100644 --- a/xen-hvm.c +++ b/xen-hvm.c @@ -242,10 +242,6 @@ static void xen_ram_init(PCMachineState *pcms, void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, Error **errp) { - unsigned long nr_pfn; - xen_pfn_t *pfn_list; - int i; - if (runstate_check(RUN_STATE_INMIGRATE)) { /* RAM already populated in Xen */ fprintf(stderr, "%s: do not alloc "RAM_ADDR_FMT @@ -259,20 +255,13 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, } trace_xen_ram_alloc(ram_addr, size); - - nr_pfn = size >> TARGET_PAGE_BITS; - pfn_list = g_malloc(sizeof (*pfn_list) * nr_pfn); - - for (i = 0; i < nr_pfn; i++) { - pfn_list[i] = (ram_addr >> TARGET_PAGE_BITS) + i; - } - - if (xc_domain_populate_physmap_exact(xen_xc, xen_domid, nr_pfn, 0, 0, pfn_list)) { + if (xendevicemodel_populate_ram(xen_dm, + ram_addr >> TARGET_PAGE_BITS, + size >> TARGET_PAGE_BITS)) { error_setg(errp, "xen: failed to populate ram at " RAM_ADDR_FMT, ram_addr); + /* XXX not an error? */ } - - g_free(pfn_list); } static XenPhysmap *get_physmapping(XenIOState *state, -- 2.39.5