From patchwork Tue May 3 10:21:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King X-Patchwork-Id: 9002391 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E45B8BF29F for ; Tue, 3 May 2016 10:25:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 16D7C2010C for ; Tue, 3 May 2016 10:25:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3AC7B200E9 for ; Tue, 3 May 2016 10:25:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1axXUH-0000cC-VK; Tue, 03 May 2016 10:23:30 +0000 Received: from pandora.arm.linux.org.uk ([78.32.30.218]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1axXTZ-0007YI-Vu for linux-arm-kernel@lists.infradead.org; Tue, 03 May 2016 10:22:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora-2014; h=Date:Sender:Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References:In-Reply-To; bh=kPzlc6QMvfrUUH0bpyF9OGd27aanYqVP7EaLIaqnolY=; b=mSGXwk71CzJ6vZZMZ52inRV9S/FAuWAXRw/KqvHf4HWRLMvPy63VvDNh8au7OujXrYp0q1dAW802wcPsmx2XD/ZYV17yQTXPWK9UzgDeotYlGz774v4qXF8FWgM3fM91lSuFslIH6LN572JpO7IL00bhPrp0gzoX6CbE00Fl3IA=; Received: from [2002:4e20:1eda:1:452d:3855:1c55:6d46] (port=42720 helo=e0050434b2927.dyn.arm.linux.org.uk) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES128-SHA:128) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1axXSu-0004wh-CO; Tue, 03 May 2016 11:22:05 +0100 Received: from rmk by e0050434b2927.dyn.arm.linux.org.uk with local (Exim 4.82) (envelope-from ) id 1axXSl-0004hr-0T; Tue, 03 May 2016 11:21:55 +0100 In-Reply-To: References: From: Russell King To: kexec@lists.infradead.org,linux-arm-kernel@lists.infradead.org Subject: [PATCH kexec-tools 10/32] kexec: add generic helper to add to memory_regions MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Tue, 03 May 2016 11:21:55 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160503_032247_138958_CD7CF166 X-CRM114-Status: GOOD ( 17.07 ) X-Spam-Score: -3.0 (---) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pratyush Anand Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a helper to add a memory range to a memory_regions array. Signed-off-by: Russell King Reviewed-by: Pratyush Anand --- kexec/Makefile | 4 ++++ kexec/mem_regions.c | 30 ++++++++++++++++++++++++++++++ kexec/mem_regions.h | 9 +++++++++ 3 files changed, 43 insertions(+) create mode 100644 kexec/mem_regions.c create mode 100644 kexec/mem_regions.h diff --git a/kexec/Makefile b/kexec/Makefile index a758b4a..e2aee84 100644 --- a/kexec/Makefile +++ b/kexec/Makefile @@ -69,6 +69,10 @@ dist += kexec/fs2dt.c kexec/fs2dt.h $(ARCH)_FS2DT = KEXEC_SRCS += $($(ARCH)_FS2DT) +dist += kexec/mem_regions.c kexec/mem_regions.h +$(ARCH)_MEM_REGIONS = +KEXEC_SRCS += $($(ARCH)_MEM_REGIONS) + include $(srcdir)/kexec/arch/alpha/Makefile include $(srcdir)/kexec/arch/arm/Makefile include $(srcdir)/kexec/arch/i386/Makefile diff --git a/kexec/mem_regions.c b/kexec/mem_regions.c new file mode 100644 index 0000000..a4952ff --- /dev/null +++ b/kexec/mem_regions.c @@ -0,0 +1,30 @@ +#include "kexec.h" +#include "mem_regions.h" + +/** + * mem_regions_add() - add a memory region to a set of ranges + * @ranges: ranges to add the memory region to + * @max: maximum number of entries in memory region + * @base: base address of memory region + * @length: length of memory region in bytes + * @type: type of memory region + * + * Add the memory region to the set of ranges, and return %0 if successful, + * or %-1 if we ran out of space. + */ +int mem_regions_add(struct memory_ranges *ranges, unsigned long long base, + unsigned long long length, int type) +{ + struct memory_range *range; + + if (ranges->size >= ranges->max_size) + return -1; + + range = ranges->ranges + ranges->size++; + range->start = base; + range->end = base + length - 1; + range->type = type; + + return 0; +} + diff --git a/kexec/mem_regions.h b/kexec/mem_regions.h new file mode 100644 index 0000000..b9cfba1 --- /dev/null +++ b/kexec/mem_regions.h @@ -0,0 +1,9 @@ +#ifndef MEM_REGIONS_H +#define MEM_REGIONS_H + +struct memory_ranges; + +int mem_regions_add(struct memory_ranges *ranges, unsigned long long base, + unsigned long long length, int type); + +#endif