From patchwork Tue May 13 11:29:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 30031 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f197.google.com (mail-ig0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 44E7620369 for ; Tue, 13 May 2014 11:31:05 +0000 (UTC) Received: by mail-ig0-f197.google.com with SMTP id hn18sf804312igb.8 for ; Tue, 13 May 2014 04:31:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=+GuIZ/d/pUMyJu8MuGPZvvx6QW3pqm/QicNV3k55GoA=; b=FTAYZrTp1e8aPGn3RsgL4qJc1f+NuMTAFmqiIOPb8hFBe6l6h+q9ZOI7ybGepv1/BM jdzQ3GJ1xqeZaaJxMhF6xSdz7N88eY8Igyo/yOvgoLQEgn+SJq9XVrpin7XTJZ30KfLa H0q+6g3Ln7L6UIFeHydM+bbmGkDMpQ0NjpqLGeSZRqzc+FcfQsyVfLOPb3w/efdZyOk2 XEXEriZplfIG8ktKVFEUj59+O/csfjkUrE/6hdRdqjQL/KRK0n4lsBs1DWnLUuqWSf1k 9HJ6fGDVCd3z8JPi94d9rSA4cmYKQth8HxllyFZd+UWcViSHQR1Xjv4/DLiQfaDXMzXl pLhA== X-Gm-Message-State: ALoCoQkE5Fi46NrZJB93F9t4v9kY1NWraLKixG1znCPQdjpey+yVueuzfR5QlwSbj7GIjiDttq+d X-Received: by 10.50.43.228 with SMTP id z4mr14197204igl.0.1399980664767; Tue, 13 May 2014 04:31:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.131 with SMTP id d3ls1890597qge.52.gmail; Tue, 13 May 2014 04:31:04 -0700 (PDT) X-Received: by 10.220.5.10 with SMTP id 10mr15459vct.40.1399980664643; Tue, 13 May 2014 04:31:04 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id gq7si2578355vdc.212.2014.05.13.04.31.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 04:31:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id lc6so236067vcb.30 for ; Tue, 13 May 2014 04:31:04 -0700 (PDT) X-Received: by 10.52.125.198 with SMTP id ms6mr2679854vdb.28.1399980664549; Tue, 13 May 2014 04:31:04 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp143335vcb; Tue, 13 May 2014 04:31:04 -0700 (PDT) X-Received: by 10.220.190.197 with SMTP id dj5mr28340967vcb.19.1399980664136; Tue, 13 May 2014 04:31:04 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id ui2si2583760vdc.118.2014.05.13.04.31.03 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 13 May 2014 04:31:04 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WkAu6-00082h-TM; Tue, 13 May 2014 11:29:50 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WkAu4-0007yp-4w for xen-devel@lists.xen.org; Tue, 13 May 2014 11:29:48 +0000 Received: from [85.158.139.211:7428] by server-12.bemta-5.messagelabs.com id 0D/A1-03824-B2202735; Tue, 13 May 2014 11:29:47 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-2.tower-206.messagelabs.com!1399980578!3948814!3 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 2594 invoked from network); 13 May 2014 11:29:46 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-2.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 13 May 2014 11:29:46 -0000 X-IronPort-AV: E=Sophos; i="4.97,1043,1389744000"; d="scan'208"; a="130584609" Received: from accessns.citrite.net (HELO FTLPEX01CL03.citrite.net) ([10.9.154.239]) by FTLPIPO01.CITRIX.COM with ESMTP; 13 May 2014 11:29:47 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.80) with Microsoft SMTP Server id 14.3.181.6; Tue, 13 May 2014 07:29:45 -0400 Received: from marilith-n13-p0.uk.xensource.com ([10.80.229.115] helo=localhost.localdomain) by ukmail1.uk.xensource.com with smtp (Exim 4.69) (envelope-from ) id 1WkAtw-0004Xn-Of; Tue, 13 May 2014 12:29:41 +0100 Received: by localhost.localdomain (sSMTP sendmail emulation); Tue, 13 May 2014 12:29:40 +0100 From: Ian Campbell To: Date: Tue, 13 May 2014 12:29:31 +0100 Message-ID: <1399980574-12515-7-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1399980488.21867.19.camel@kazak.uk.xensource.com> References: <1399980488.21867.19.camel@kazak.uk.xensource.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: ian.jackson@eu.citrix.com, julien.grall@linaro.org, tim@xen.org, Ian Campbell , stefano.stabellini@eu.citrix.com Subject: [Xen-devel] [PATCH v4 7/9] tools: arm: prepare guest FDT building for multiple RAM banks X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ian.campbell@citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: This required exposing the sizes of the banks determined by the domain builder up to libxl via xc_dom_image. Since the domain build needs to know the size of the DTB we create placeholder nodes for each possible bank and when we finialise the DTB we fill in the ones which are actually populated and NOP out the rest. Note that the number of guest RAM banks is still 1 after this change. Signed-off-by: Ian Campbell --- v4: New patch --- tools/libxc/xc_dom.h | 10 +++++- tools/libxc/xc_dom_arm.c | 12 +++----- tools/libxl/libxl_arm.c | 77 ++++++++++++++++++++++++++++++++++++---------- 3 files changed, 74 insertions(+), 25 deletions(-) diff --git a/tools/libxc/xc_dom.h b/tools/libxc/xc_dom.h index c9af0ce..6ae6a9f 100644 --- a/tools/libxc/xc_dom.h +++ b/tools/libxc/xc_dom.h @@ -114,13 +114,21 @@ struct xc_dom_image { /* physical memory * - * A PV guest has a single contiguous block of physical RAM, + * An x86 PV guest has a single contiguous block of physical RAM, * consisting of total_pages starting at rambase_pfn. + * + * An ARM guest has GUEST_RAM_BANKS regions of RAM, with + * rambank_size[i] pages in each. The lowest RAM address + * (corresponding to the base of the p2m arrays above) is stored + * in rambase_pfn. */ xen_pfn_t rambase_pfn; xen_pfn_t total_pages; struct xc_dom_phys *phys_pages; int realmodearea_log; +#if defined (__arm__) || defined(__aarch64__) + xen_pfn_t rambank_size[GUEST_RAM_BANKS]; +#endif /* malloc memory pool */ struct xc_dom_mem *memblocks; diff --git a/tools/libxc/xc_dom_arm.c b/tools/libxc/xc_dom_arm.c index 6c255ac..c83965d 100644 --- a/tools/libxc/xc_dom_arm.c +++ b/tools/libxc/xc_dom_arm.c @@ -305,7 +305,6 @@ int arch_setup_meminit(struct xc_dom_image *dom) const uint64_t ram128mb = GUEST_RAM0_BASE + (128<<20); xen_pfn_t p2m_size; - xen_pfn_t rambank_size[GUEST_RAM_BANKS]; uint64_t bank0end; assert(dom->rambase_pfn << XC_PAGE_SHIFT == GUEST_RAM0_BASE); @@ -345,10 +344,10 @@ int arch_setup_meminit(struct xc_dom_image *dom) p2m_size = ( bankbase[i] + banksize - bankbase[0] ) >> XC_PAGE_SHIFT; - rambank_size[i] = banksize >> XC_PAGE_SHIFT; + dom->rambank_size[i] = banksize >> XC_PAGE_SHIFT; } - assert(rambank_size[0] != 0); + assert(dom->rambank_size[0] != 0); assert(ramsize == 0); /* Too much RAM is rejected above */ dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * p2m_size); @@ -358,11 +357,10 @@ int arch_setup_meminit(struct xc_dom_image *dom) dom->p2m_host[pfn] = INVALID_MFN; /* setup initial p2m and allocate guest memory */ - for (i = 0; rambank_size[i] && i < GUEST_RAM_BANKS; i++) - { + for (i = 0; dom->rambank_size[i] && i < GUEST_RAM_BANKS; i++) { if ((rc = populate_guest_memory(dom, bankbase[i] >> XC_PAGE_SHIFT, - rambank_size[i]))) + dom->rambank_size[i]))) return rc; } @@ -374,7 +372,7 @@ int arch_setup_meminit(struct xc_dom_image *dom) * If changing this then consider * xen/arch/arm/kernel.c:place_modules as well. */ - bank0end = bankbase[0] + ((uint64_t)rambank_size[0] << XC_PAGE_SHIFT); + bank0end = bankbase[0] + ((uint64_t)dom->rambank_size[0] << XC_PAGE_SHIFT); if ( bank0end >= ram128mb + modsize && kernend < ram128mb ) modbase = ram128mb; diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c index 215ef9e..90fca67 100644 --- a/tools/libxl/libxl_arm.c +++ b/tools/libxl/libxl_arm.c @@ -255,24 +255,33 @@ static int make_psci_node(libxl__gc *gc, void *fdt) return 0; } -static int make_memory_node(libxl__gc *gc, void *fdt, - uint64_t base, uint64_t size) +static int make_memory_nodes(libxl__gc *gc, void *fdt, + const struct xc_dom_image *dom) { - int res; - const char *name = GCSPRINTF("memory@%"PRIx64, base); + int res, i; + const char *name; + const uint64_t bankbase[GUEST_RAM_BANKS] = { + GUEST_RAM0_BASE + }; - res = fdt_begin_node(fdt, name); - if (res) return res; + for (i = 0; i < GUEST_RAM_BANKS; i++) { + name = GCSPRINTF("memory@%"PRIx64, bankbase[i]); - res = fdt_property_string(fdt, "device_type", "memory"); - if (res) return res; + LOG(DEBUG, "Creating placeholder node /%s", name); - res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS, - 1, base, size); - if (res) return res; + res = fdt_begin_node(fdt, name); + if (res) return res; - res = fdt_end_node(fdt); - if (res) return res; + res = fdt_property_string(fdt, "device_type", "memory"); + if (res) return res; + + res = fdt_property_regs(gc, fdt, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS, + 1, 0, 0); + if (res) return res; + + res = fdt_end_node(fdt); + if (res) return res; + } return 0; } @@ -489,9 +498,7 @@ next_resize: FDT( make_cpus_node(gc, fdt, info->max_vcpus, ainfo) ); FDT( make_psci_node(gc, fdt) ); - FDT( make_memory_node(gc, fdt, - dom->rambase_pfn << XC_PAGE_SHIFT, - info->target_memkb * 1024) ); + FDT( make_memory_nodes(gc, fdt, dom) ); FDT( make_intc_node(gc, fdt, GUEST_GICD_BASE, GUEST_GICD_SIZE, GUEST_GICC_BASE, GUEST_GICD_SIZE) ); @@ -521,11 +528,40 @@ out: return rc; } +static void finalise_one_memory_node(libxl__gc *gc, void *fdt, + uint64_t base, uint64_t size) +{ + int node, res; + const char *name = GCSPRINTF("/memory@%"PRIx64, base); + + node = fdt_path_offset(fdt, name); + assert(node > 0); + + if (size == 0) { + LOG(DEBUG, "Nopping out placeholder node %s", name); + fdt_nop_node(fdt, node); + } else { + uint32_t regs[ROOT_ADDRESS_CELLS+ROOT_SIZE_CELLS]; + be32 *cells = ®s[0]; + + LOG(DEBUG, "Populating placeholder node %s", name); + + set_range(&cells, ROOT_ADDRESS_CELLS, ROOT_SIZE_CELLS, base, size); + + res = fdt_setprop_inplace(fdt, node, "reg", regs, sizeof(regs)); + assert(!res); + } +} + int libxl__arch_domain_finalise_hw_description(libxl__gc *gc, libxl_domain_build_info *info, struct xc_dom_image *dom) { void *fdt = dom->devicetree_blob; + int i; + const uint64_t bankbase[GUEST_RAM_BANKS] = { + GUEST_RAM0_BASE + }; const struct xc_dom_seg *ramdisk = dom->ramdisk_blob ? &dom->ramdisk_seg : NULL; @@ -552,9 +588,16 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc *gc, assert(!res); val = cpu_to_fdt64(ramdisk->vend); - res = fdt_setprop_inplace(fdt, chosen,PROP_INITRD_END, + res = fdt_setprop_inplace(fdt, chosen, PROP_INITRD_END, &val, sizeof(val)); assert(!res); + + } + + for (i = 0; i < GUEST_RAM_BANKS; i++) { + const uint64_t size = (uint64_t)dom->rambank_size[i] << XC_PAGE_SHIFT; + + finalise_one_memory_node(gc, fdt, bankbase[i], size); } debug_dump_fdt(gc, fdt);