From patchwork Wed Mar 8 17:54:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 95050 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp22452obz; Wed, 8 Mar 2017 09:56:51 -0800 (PST) X-Received: by 10.36.1.208 with SMTP id 199mr20712670itk.20.1488995811373; Wed, 08 Mar 2017 09:56:51 -0800 (PST) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id v83si4590164iod.67.2017.03.08.09.56.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Mar 2017 09:56:51 -0800 (PST) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 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 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1clfnV-0005wd-QD; Wed, 08 Mar 2017 17:54:49 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1clfnU-0005w0-P5 for xen-devel@lists.xen.org; Wed, 08 Mar 2017 17:54:48 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id FD/AE-06437-86540C85; Wed, 08 Mar 2017 17:54:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRWlGSWpSXmKPExsVysyfVTTfd9UC EwdaX0hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa0br3gusBe8kKvpntLE1MB4W6mLk5BAS2Mwo 8WKXRBcjF5B9mlHi/c0frCAJNgFNiTufPzGB2CIC0hLXPl9mBLGZBRwk3ny8xwJiCwskS7Q2v gKLswioSux7/outi5GDg1fAUmL9WweQsISAvMSutotgIzkFrCTeNn1lgdhrKfF9zke2CYzcCx gZVjFqFKcWlaUW6RoZ6iUVZaZnlOQmZuboGhoY6+WmFhcnpqfmJCYV6yXn525iBHq3noGBcQd jz16/Q4ySHExKorxXVQ9ECPEl5adUZiQWZ8QXleakFh9ilOHgUJLgjXYBygkWpaanVqRl5gDD DCYtwcGjJMK7DyTNW1yQmFucmQ6ROsWoKCXO6wuSEABJZJTmwbXBQvsSo6yUMC8jAwODEE9Ba lFuZgmq/CtGcQ5GJWHeq85AU3gy80rgpr8CWswEtFjbdS/I4pJEhJRUA6PPS/1mw0Zb58nLpS Kjcv7Uck5O/7/iUlfM0pai0j+9dfxSRQ5GRQXJPTynHlb8t5J7qW63foelU1GUbcSq4uV70ln SzkcdjZd4I/bkZtXTWw4b/63ffKogzFC4JqXz9pamLN8PG3sK8zU3XOXZGrj5bNoHnz6xppdJ akLJ6f7sF8+ffvd3kRJLcUaioRZzUXEiAA3dRJRoAgAA X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1488995686!58387098!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3797 invoked from network); 8 Mar 2017 17:54:47 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-11.tower-31.messagelabs.com with SMTP; 8 Mar 2017 17:54:47 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 798AA1500; Wed, 8 Mar 2017 09:54:46 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.218.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CBDF63F23B; Wed, 8 Mar 2017 09:54:45 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Wed, 8 Mar 2017 17:54:34 +0000 Message-Id: <20170308175436.24001-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170308175436.24001-1-julien.grall@arm.com> References: <20170308175436.24001-1-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v2 2/4] xen/arm: efi: Avoid duplicating the addition of a new efi memory descriptor X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" The code to add a new memory descriptor is duplicated three times. Add a new helper that adds the descriptor. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by --- xen/arch/arm/efi/efi-dom0.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/efi/efi-dom0.c b/xen/arch/arm/efi/efi-dom0.c index c40a7c50f3..f307f26bf6 100644 --- a/xen/arch/arm/efi/efi-dom0.c +++ b/xen/arch/arm/efi/efi-dom0.c @@ -96,6 +96,18 @@ void __init acpi_create_efi_system_table(struct domain *d, tbl_add[TBL_EFIT].size = table_size; } +static void __init fill_efi_memory_descriptor(EFI_MEMORY_DESCRIPTOR *desc, + UINT32 type, + EFI_PHYSICAL_ADDRESS start, + UINT64 size) +{ + desc->Type = type; + desc->PhysicalStart = start; + BUG_ON(size & EFI_PAGE_MASK); + desc->NumberOfPages = EFI_SIZE_TO_PAGES(size); + desc->Attribute = EFI_MEMORY_WB; +} + void __init acpi_create_efi_mmap_table(struct domain *d, const struct meminfo *mem, struct membank tbl_add[]) @@ -110,28 +122,16 @@ void __init acpi_create_efi_mmap_table(struct domain *d, offset = 0; for( i = 0; i < mem->nr_banks; i++, offset++ ) - { - memory_map[offset].Type = EfiConventionalMemory; - memory_map[offset].PhysicalStart = mem->bank[i].start; - BUG_ON(mem->bank[i].size & EFI_PAGE_MASK); - memory_map[offset].NumberOfPages = EFI_SIZE_TO_PAGES(mem->bank[i].size); - memory_map[offset].Attribute = EFI_MEMORY_WB; - } + fill_efi_memory_descriptor(&memory_map[offset], EfiConventionalMemory, + mem->bank[i].start, mem->bank[i].size); for( i = 0; i < acpi_mem.nr_banks; i++, offset++ ) - { - memory_map[offset].Type = EfiACPIReclaimMemory; - memory_map[offset].PhysicalStart = acpi_mem.bank[i].start; - BUG_ON(acpi_mem.bank[i].size & EFI_PAGE_MASK); - memory_map[offset].NumberOfPages = EFI_SIZE_TO_PAGES(acpi_mem.bank[i].size); - memory_map[offset].Attribute = EFI_MEMORY_WB; - } - - memory_map[offset].Type = EfiACPIReclaimMemory; - memory_map[offset].PhysicalStart = d->arch.efi_acpi_gpa; - BUG_ON(d->arch.efi_acpi_len & EFI_PAGE_MASK); - memory_map[offset].NumberOfPages = EFI_SIZE_TO_PAGES(d->arch.efi_acpi_len); - memory_map[offset].Attribute = EFI_MEMORY_WB; + fill_efi_memory_descriptor(&memory_map[offset], EfiACPIReclaimMemory, + acpi_mem.bank[i].start, + acpi_mem.bank[i].size); + + fill_efi_memory_descriptor(&memory_map[offset], EfiACPIReclaimMemory, + d->arch.efi_acpi_gpa, d->arch.efi_acpi_len); tbl_add[TBL_MMAP].start = d->arch.efi_acpi_gpa + acpi_get_table_offset(tbl_add, TBL_MMAP);