From patchwork Tue Nov 17 09:40:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 56741 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1827216lbb; Tue, 17 Nov 2015 01:48:21 -0800 (PST) X-Received: by 10.140.250.70 with SMTP id v67mr7292441qhc.43.1447753700316; Tue, 17 Nov 2015 01:48:20 -0800 (PST) Return-Path: Received: from lists.xen.org (lists.xenproject.org. [50.57.142.19]) by mx.google.com with ESMTPS id 77si29115418qhh.73.2015.11.17.01.48.20 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 17 Nov 2015 01:48:20 -0800 (PST) Received-SPF: neutral (google.com: 50.57.142.19 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=50.57.142.19; Authentication-Results: mx.google.com; spf=neutral (google.com: 50.57.142.19 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Zycqw-0006Tm-Bp; Tue, 17 Nov 2015 09:47:06 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Zycqu-0006SD-Nq for xen-devel@lists.xen.org; Tue, 17 Nov 2015 09:47:04 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id D6/40-13487-797FA465; Tue, 17 Nov 2015 09:47:03 +0000 X-Env-Sender: shannon.zhao@linaro.org X-Msg-Ref: server-5.tower-206.messagelabs.com!1447753622!4237534!1 X-Originating-IP: [74.125.82.46] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.19.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 50534 invoked from network); 17 Nov 2015 09:47:02 -0000 Received: from mail-wm0-f46.google.com (HELO mail-wm0-f46.google.com) (74.125.82.46) by server-5.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 17 Nov 2015 09:47:02 -0000 Received: by wmec201 with SMTP id c201so218070351wme.0 for ; Tue, 17 Nov 2015 01:47:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=A3uALaihuDnFHN3WzDWSgfHqpKp0QmhkSZx4RH8VZTU=; b=IisPTMTbtydVVO51JjxDkcQhhPRCBLBq9OkwD+GTSssZbArGa9jrqpafg8gbf1BOzP Q3JqqVzU8wx0i/elXKK1yHoxK6qhW+/4cYiUBLufgMq2H/fmat32uo7xn0+ptoeWr1id fkoMs2zFk3w29EntXvIvTqwQIhTLjnlLj2oRl7Z9S0/V8KooP5UFAptlt44xz/uqZsU5 7P+HmPJBJ/lOOJs0Da2LeCUn33hd+ITEzP01ojsNQee8meL0ussRCFAhnP/2iVY2NTWL WHEbucgKKb0njUV9ELM+/c+SkiN9xzTsin1CQbiGdsDhzwsKU4TCQFzxPF8APcRXtSsn Kr0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=A3uALaihuDnFHN3WzDWSgfHqpKp0QmhkSZx4RH8VZTU=; b=UD/LdZQmYrfIQ9qmoH3QXLUcp/C27S2kaqdGVjltvePpCnbiCTEb3g8SDdwJ+l7NaQ kwuqRfaMQ82F8vC66uedVg4Kl81GlsrVFqLPnWsAh+KrLz/jSBYd4b3eQkN6xZS+E2SH HG6oB60lad6H7l4BN6ZRpCRMcmnXUgBYTFMXbv+3RLrrs4hJ4/56P1tPZ0cZscDnCjW1 m1TGEtdGyerAio8U+fo18+XvVbFD4a8Js/8gpvn8N2GUlp4m6C2RQVU3TSRL3To+TGg5 9PNNT6TJ7IIWFDTnpIw0TRfDFzeFvXXlTVxrbmK8RnsPlxVtZ8ftmZualK6OkCjFdqqZ 8FEQ== X-Gm-Message-State: ALoCoQkWEj2ktCEx25j0Z2UmE2UkSRavDRonyeuZgHJG8OXWobqc4ikPeU0Y18/GtK2ZUSaPZgHR X-Received: by 10.28.218.7 with SMTP id r7mr1406605wmg.17.1447753622314; Tue, 17 Nov 2015 01:47:02 -0800 (PST) Received: from localhost ([78.129.251.54]) by smtp.gmail.com with ESMTPSA id n127sm11759310wmf.12.2015.11.17.01.46.59 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 17 Nov 2015 01:47:01 -0800 (PST) From: shannon.zhao@linaro.org To: ian.campbell@citrix.com, stefano.stabellini@citrix.com, keir@xen.org, jbeulich@suse.com, andrew.cooper3@citrix.com, julien.grall@citrix.com, xen-devel@lists.xen.org Date: Tue, 17 Nov 2015 17:40:39 +0800 Message-Id: <1447753261-7552-41-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1447753261-7552-1-git-send-email-shannon.zhao@linaro.org> References: <1447753261-7552-1-git-send-email-shannon.zhao@linaro.org> Cc: mark.rutland@arm.com, hangaohuai@huawei.com, ard.biesheuvel@linaro.org, shannon.zhao@linaro.org, christoffer.dall@linaro.org, peter.huangpeng@huawei.com, david.vrabel@citrix.com, zhaoshenglong@huawei.com, linux-arm-kernel@lists.infradead.org, roger.pau@citrix.com Subject: [Xen-devel] [PATCH v3 40/62] arm/acpi: Estimate memory required for acpi/efi tables X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org From: Shannon Zhao Estimate the memory required for loading acpi/efi tables in Dom0. Alloc the pages to store the new created EFI and ACPI tables and free these pages when destroying domain. Signed-off-by: Parth Dixit Signed-off-by: Shannon Zhao --- xen/arch/arm/domain.c | 4 +++ xen/arch/arm/domain_build.c | 80 ++++++++++++++++++++++++++++++++++++++++++++- xen/common/efi/boot.c | 21 ++++++++++++ xen/include/asm-arm/setup.h | 2 ++ 4 files changed, 106 insertions(+), 1 deletion(-) -- 2.1.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 880d0a6..10c58c4 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -638,6 +638,10 @@ void arch_domain_destroy(struct domain *d) domain_vgic_free(d); domain_vuart_free(d); free_xenheap_page(d->shared_info); +#ifdef CONFIG_ACPI + free_xenheap_pages(d->arch.efi_acpi_table, + get_order_from_bytes(d->arch.efi_acpi_len)); +#endif } void arch_domain_shutdown(struct domain *d) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 0c3441a..b5ed44c 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -1354,6 +1356,78 @@ static int prepare_dtb(struct domain *d, struct kernel_info *kinfo) return -EINVAL; } +#ifdef CONFIG_ACPI +static int estimate_acpi_efi_size(struct domain *d, struct kernel_info *kinfo) +{ + u64 efi_size, acpi_size = 0, addr; + u32 madt_size; + struct acpi_table_rsdp *rsdp_tbl; + struct acpi_table_header *table = NULL; + + efi_size = estimate_efi_size(kinfo->mem.nr_banks); + + acpi_size += PAGE_ALIGN(sizeof(struct acpi_table_fadt)); + acpi_size += PAGE_ALIGN(sizeof(struct acpi_table_stao)); + + madt_size = sizeof(struct acpi_table_madt) + + sizeof(struct acpi_madt_generic_interrupt) * d->max_vcpus + + sizeof(struct acpi_madt_generic_distributor); + if ( d->arch.vgic.version == GIC_V3 ) + madt_size += sizeof(struct acpi_madt_generic_redistributor) + * d->arch.vgic.nr_regions; + acpi_size += PAGE_ALIGN(madt_size); + + addr = acpi_os_get_root_pointer(); + if ( !addr ) + { + printk("Unable to get acpi root pointer\n"); + return -EINVAL; + } + rsdp_tbl = acpi_os_map_memory(addr, sizeof(struct acpi_table_rsdp)); + table = acpi_os_map_memory(rsdp_tbl->xsdt_physical_address, + sizeof(struct acpi_table_header)); + acpi_size += PAGE_ALIGN(table->length + sizeof(u64)); + acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); + acpi_os_unmap_memory(rsdp_tbl, sizeof(struct acpi_table_rsdp)); + + acpi_size += PAGE_ALIGN(sizeof(struct acpi_table_rsdp)); + d->arch.efi_acpi_len = PAGE_ALIGN(efi_size) + PAGE_ALIGN(acpi_size); + + return 0; +} + +static int prepare_acpi(struct domain *d, struct kernel_info *kinfo) +{ + int rc = 0; + int order; + + rc = estimate_acpi_efi_size(d, kinfo); + if ( rc != 0 ) + return rc; + + order = get_order_from_bytes(d->arch.efi_acpi_len); + d->arch.efi_acpi_table = alloc_xenheap_pages(order, 0); + if ( d->arch.efi_acpi_table == NULL ) + { + printk("unable to allocate memory!\n"); + return -1; + } + memset(d->arch.efi_acpi_table, 0, d->arch.efi_acpi_len); + + /* For ACPI, Dom0 doesn't use kinfo->gnttab_start to get the grant table + * region. So we use it as the ACPI table mapped address. */ + d->arch.efi_acpi_gpa = kinfo->gnttab_start; + + return 0; +} +#else +static int prepare_acpi(struct domain *d, struct kernel_info *kinfo) +{ + /* Only booting with ACPI will hit here */ + BUG_ON(1); + return -EINVAL; +} +#endif static void dtb_load(struct kernel_info *kinfo) { void * __user dtb_virt = (void * __user)(register_t)kinfo->dtb_paddr; @@ -1540,7 +1614,11 @@ int construct_dom0(struct domain *d) allocate_memory(d, &kinfo); find_gnttab_region(d, &kinfo); - rc = prepare_dtb(d, &kinfo); + if ( acpi_disabled ) + rc = prepare_dtb(d, &kinfo); + else + rc = prepare_acpi(d, &kinfo); + if ( rc < 0 ) return rc; diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 53c7452..78d8ae9 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -13,6 +13,7 @@ #include #include #include +#include #if EFI_PAGE_SIZE != PAGE_SIZE # error Cannot use xen/pfn.h here! #endif @@ -1171,6 +1172,26 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) for( ; ; ); /* not reached */ } +#ifdef CONFIG_ACPI +/* Constant to indicate "Xen" in unicode u16 format */ +static const u16 XEN_EFI_FW_VENDOR[] ={0x0058,0x0065,0x006E,0x0000}; + +int __init estimate_efi_size(int mem_nr_banks) +{ + int size; + int est_size = sizeof(EFI_SYSTEM_TABLE); + int ect_size = sizeof(EFI_CONFIGURATION_TABLE); + int emd_size = sizeof(EFI_MEMORY_DESCRIPTOR); + int fw_vendor_size = sizeof(XEN_EFI_FW_VENDOR); + + size = PAGE_ALIGN(est_size + ect_size + fw_vendor_size) + + PAGE_ALIGN(emd_size * + (mem_nr_banks + acpi_mem.nr_banks + TBL_MMAX)); + + return size; +} +#endif + #ifndef CONFIG_ARM /* TODO - runtime service support */ static bool_t __initdata efi_rs_enable = 1; diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h index 30ac53b..b759813 100644 --- a/xen/include/asm-arm/setup.h +++ b/xen/include/asm-arm/setup.h @@ -51,6 +51,8 @@ void arch_init_memory(void); void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len); +int estimate_efi_size(int mem_nr_banks); + int construct_dom0(struct domain *d); void discard_initial_modules(void);