From patchwork Tue Jul 26 07:56:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 72775 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1548873qga; Tue, 26 Jul 2016 00:55:02 -0700 (PDT) X-Received: by 10.98.152.129 with SMTP id d1mr37399551pfk.126.1469519702816; Tue, 26 Jul 2016 00:55:02 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id u79si38050248pfj.150.2016.07.26.00.55.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jul 2016 00:55:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bRxBh-0001Cl-9Z; Tue, 26 Jul 2016 07:54:01 +0000 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bRxAo-0000Xt-VN for linux-arm-kernel@lists.infradead.org; Tue, 26 Jul 2016 07:53:14 +0000 Received: by mail-pf0-x230.google.com with SMTP id x72so72899153pfd.2 for ; Tue, 26 Jul 2016 00:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S9nzlWvmZpfKi9Hx+qOpwtT6voPlu+3p8h0V8ifoqXE=; b=Q2tgH4dQEXXn+RGFBMuzI1B1csV4lsGXwpeEHXBEfak/RkwitZfJ5toihYjFisC4eM Q+PxqldLxuUbkyUWKnuszRmjQn92xiqEEGtAf0ntYlRlsdjkxTbuFvVxhDuZl1EPAngi SNxUfsBSISGdrYsjj+twyHpbMUBkjpq8hEWC8= 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=S9nzlWvmZpfKi9Hx+qOpwtT6voPlu+3p8h0V8ifoqXE=; b=YXF54XFJ42dPf2H/p5H/gVt3YJvh7ZrpvYMlH2I1Kx8BVElGS1v5078YsDAIDRB8kN K0vKsUwyPDfchJF2tp2Dz6peINKoQylFCJqC8CsHlxtSY3n+jysh20Y4J62knA2KntNj SlyMDctrPx8tTD/DRqtowF9LAvadC8eOb/tVm+kgy1/Cp7iScLRGDj7GNZ/rHOHyHsLW 1xAnEGtMEOxwzc/dIgxcszWFS9n9jdATxtFFtFMlUM/BWLGVkDi4pV0n3hybkm514u9W PLvoBILWECWNef17IesXxOfkAkEI6ziJFUmizkK61Qfeh5zFtdqzp8oU93dt50Qn5SQW pHaw== X-Gm-Message-State: AEkooutezfDXwGe/mcSoGvAByDQ9uxH640i8p2aGwqlFDP+vwyfhDxc5/1PjRsRwG5HOhGW2 X-Received: by 10.98.152.129 with SMTP id d1mr37385765pfk.126.1469519565582; Tue, 26 Jul 2016 00:52:45 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g10sm45328800pfc.57.2016.07.26.00.52.44 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 26 Jul 2016 00:52:45 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com Subject: [PATCH v23 2/9] memblock: add memblock_cap_memory_range() Date: Tue, 26 Jul 2016 16:56:53 +0900 Message-Id: <20160726075659.2290-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160726075659.2290-1-takahiro.akashi@linaro.org> References: <20160726075659.2290-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160726_005307_362211_7A6887A4 X-CRM114-Status: GOOD ( 10.59 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:400e:c00:0:0:0:230 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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: mark.rutland@arm.com, geoff@infradead.org, kexec@lists.infradead.org, AKASHI Takahiro , james.morse@arm.com, bauerman@linux.vnet.ibm.com, dyoung@redhat.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Signed-off-by: AKASHI Takahiro --- include/linux/memblock.h | 1 + mm/memblock.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) -- 2.9.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 3106ac1..9ab17a9 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -333,6 +333,7 @@ phys_addr_t memblock_mem_size(unsigned long limit_pfn); phys_addr_t memblock_start_of_DRAM(void); phys_addr_t memblock_end_of_DRAM(void); void memblock_enforce_memory_limit(phys_addr_t memory_limit); +void memblock_cap_memory_range(phys_addr_t base, phys_addr_t size); bool memblock_is_memory(phys_addr_t addr); int memblock_is_map_memory(phys_addr_t addr); int memblock_is_region_memory(phys_addr_t base, phys_addr_t size); diff --git a/mm/memblock.c b/mm/memblock.c index ac12489..30badf1 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1486,6 +1486,34 @@ void __init memblock_enforce_memory_limit(phys_addr_t limit) (phys_addr_t)ULLONG_MAX); } +void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size) +{ + int start_rgn, end_rgn; + int i, ret; + + if (!size) + return; + + ret = memblock_isolate_range(&memblock.memory, base, size, + &start_rgn, &end_rgn); + if (ret) + return; + + /* remove all the MAP regions */ + for (i = memblock.memory.cnt - 1; i >= end_rgn; i--) + if (!memblock_is_nomap(&memblock.memory.regions[i])) + memblock_remove_region(&memblock.memory, i); + + for (i = start_rgn - 1; i >= 0; i--) + if (!memblock_is_nomap(&memblock.memory.regions[i])) + memblock_remove_region(&memblock.memory, i); + + /* truncate the reserved regions */ + memblock_remove_range(&memblock.reserved, 0, base); + memblock_remove_range(&memblock.reserved, + base + size, (phys_addr_t)ULLONG_MAX); +} + static int __init_memblock memblock_search(struct memblock_type *type, phys_addr_t addr) { unsigned int left = 0, right = type->cnt;