From patchwork Mon Dec 4 02:57:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 120475 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3919646qgn; Sun, 3 Dec 2017 18:55:02 -0800 (PST) X-Google-Smtp-Source: AGs4zMYSJkGreLuKjrY5f4IvQNOA+pyEPL4p0mHyLPY89hAvKu+9nWh8ERdAY1JvilS8IQjUcJTC X-Received: by 10.84.179.193 with SMTP id b59mr13293165plc.12.1512356102235; Sun, 03 Dec 2017 18:55:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512356102; cv=none; d=google.com; s=arc-20160816; b=TZyWBSUB1u2CX3fxOR+m/0eFBppj2Mf41NNrs2UTE+SA089/LSSsYsQrwNz2jjo5VE gOlcqry2IgvSYXl9Rz992xZtmxq40wsc0DLTgyEmJUTtzr8823orvd39R9Rbzu25B+A/ FHA6XJJHodLztVDnNEnRLe6yXG2pyU2h+VNRwJDX7AT94DFegEh/jHyTw/5F0whJviC3 GZjIKOFypPSelmpJu120PxTxHZfC6lxN4smqNX3rTJpY9J5fK8jcf89XWcSJr+yncdfl T+nnEIY6NvIaoRfW3kCTPCYplMe3I0Wf/zDwDv7kZcewYOkrDVg0e1iC7oncDSQW3YJZ 7TrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=44Ew9lzPcyWpGu+HB4lFG4+Mr/vH9nKg0bdPyWw8+h0=; b=0j6KVjKxRmxlJXmY9Nuw43dXX6uKvEXdzdr8rC6P9ko+VdrPplsp56+N7FDlE7CFTu rqoO8zFX9PMfxPxAqNexsm+CEjwlDnY1JJslI9PeIshn1Ufri+gkBs03o7f/13Ob5hNq 37bsNp8voUQhfngTDbnQbXVkLM1okhKVw0fCDYo2whRlg7IFa3RuxKs5Z24xqadMNvT8 GiZ5whHPOqw67rq2AFhyLkRlxoMoXUNS302UrnuXMlFMl4LXrAZC4n9JsncBuuJiMLjF 3Ez5duS2FltSJAjddDXa7/1au7Hyci4+zrhgW1ib8Jcz3o5Y72aJo+QauSO5A80k8U/S 0K+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iyzh/6Qh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w15si8712279pgv.219.2017.12.03.18.55.01; Sun, 03 Dec 2017 18:55:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iyzh/6Qh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753153AbdLDCyu (ORCPT + 28 others); Sun, 3 Dec 2017 21:54:50 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35629 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753060AbdLDCyq (ORCPT ); Sun, 3 Dec 2017 21:54:46 -0500 Received: by mail-pg0-f66.google.com with SMTP id q20so7213906pgv.2 for ; Sun, 03 Dec 2017 18:54:46 -0800 (PST) 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=44Ew9lzPcyWpGu+HB4lFG4+Mr/vH9nKg0bdPyWw8+h0=; b=iyzh/6Qh7qzoOQzh5wlf7USyH6my2Jf2FC44F0oaK4rAtzC3Y4dVSxTojRRy+baZCR 5J5SLrFYoldA8VI3s2g0MqIVVKFIjN3DNT+T2i/X6AwAPE3qlWL55xGdo77FZdXRsIVP P3jfrdLoUu2SAq9ixsKiiO7leZSj3XMq99auE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=44Ew9lzPcyWpGu+HB4lFG4+Mr/vH9nKg0bdPyWw8+h0=; b=g/1MsLZ3eHdCoziAt/URfiMWg16cQTJ7frMun30Styt/mtF54YitiMsc7ggBWZvy6+ Lp3kXUd/h8BU62V5vPZ5ADADLNB3bq+m3o89fsYrfSNOOzN5TZqh1Hp4FiVL532D6iwT n2jtbQ4lZclHoUcqKWXKZvzElWCUtHfjY5+FXcCZSBmf0tStr+VleFuOdAYZQrrB/m83 EjmM6GTL4rNsFJUczpu8Yy/xwlgKShDewi8xXdtANxv1A0zTz1Q8G+u8jKjz7VVgKYtA f9VFKqrQc7paBPR4oaR9cGMUUaD19yWCuMbDInYN/VAOZ4c3u2gsVaSXBKeGJnlI0NKJ 2Ouw== X-Gm-Message-State: AJaThX6cZ5na9W1RcJMnNY1sA5rsx/0Z4ogpuT3uq2ecB6gI1IcsXzQw T/A/ktw1Ni0C2LgEbUEVSWEBMQ== X-Received: by 10.84.246.194 with SMTP id j2mr12993602plt.7.1512356085935; Sun, 03 Dec 2017 18:54:45 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id n6sm21855672pfg.188.2017.12.03.18.54.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Dec 2017 18:54:45 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , Linus Torvalds Subject: [PATCH v7 01/11] resource: add walk_system_ram_res_rev() Date: Mon, 4 Dec 2017 11:57:51 +0900 Message-Id: <20171204025801.12161-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171204025801.12161-1-takahiro.akashi@linaro.org> References: <20171204025801.12161-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function, being a variant of walk_system_ram_res() introduced in commit 8c86e70acead ("resource: provide new functions to walk through resources"), walks through a list of all the resources of System RAM in reversed order, i.e., from higher to lower. It will be used in kexec_file implementation on arm64. Signed-off-by: AKASHI Takahiro Cc: Vivek Goyal Cc: Andrew Morton Cc: Linus Torvalds --- include/linux/ioport.h | 3 +++ kernel/resource.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) -- 2.14.1 diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 93b4183cf53d..322ac1f58b36 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -277,6 +277,9 @@ extern int walk_system_ram_res(u64 start, u64 end, void *arg, int (*func)(struct resource *, void *)); extern int +walk_system_ram_res_rev(u64 start, u64 end, void *arg, + int (*func)(struct resource *, void *)); +extern int walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end, void *arg, int (*func)(struct resource *, void *)); diff --git a/kernel/resource.c b/kernel/resource.c index 54ba6de3757c..aefc1d5d6b75 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include @@ -486,6 +488,61 @@ int walk_mem_res(u64 start, u64 end, void *arg, arg, func); } +int walk_system_ram_res_rev(u64 start, u64 end, void *arg, + int (*func)(struct resource *, void *)) +{ + struct resource res, *rams; + int rams_size = 16, i; + int ret = -1; + + /* create a list */ + rams = vmalloc(sizeof(struct resource) * rams_size); + if (!rams) + return ret; + + res.start = start; + res.end = end; + res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; + i = 0; + while ((res.start < res.end) && + (!find_next_iomem_res(&res, IORES_DESC_NONE, true))) { + if (i >= rams_size) { + /* re-alloc */ + struct resource *rams_new; + int rams_new_size; + + rams_new_size = rams_size + 16; + rams_new = vmalloc(sizeof(struct resource) + * rams_new_size); + if (!rams_new) + goto out; + + memcpy(rams_new, rams, + sizeof(struct resource) * rams_size); + vfree(rams); + rams = rams_new; + rams_size = rams_new_size; + } + + rams[i].start = res.start; + rams[i++].end = res.end; + + res.start = res.end + 1; + res.end = end; + } + + /* go reverse */ + for (i--; i >= 0; i--) { + ret = (*func)(&rams[i], arg); + if (ret) + break; + } + +out: + vfree(rams); + return ret; +} + #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY) /*