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: 10089555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E332D60595 for ; Mon, 4 Dec 2017 02:56:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D79B128E4A for ; Mon, 4 Dec 2017 02:56:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC62028E4F; Mon, 4 Dec 2017 02:56:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, URIBL_DBL_ABUSE_SPAM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5092328E4A for ; Mon, 4 Dec 2017 02:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=D+0n285cNVQdzg9/7ShfTDMeTJEhMWx8YTCg9hakl0Q=; b=F7ha8YZlsdrakLcdDSCI0ymFQp 7Et/c55TV7cK/THk9c7O7pOhVBqHZoL/v6hTGYizEyv1aaoFILlXZbCkDkpaHHsLEu7KGDydh7nP1 rTm1pFq6I9I158b5B7Xx1JswR+eDKguCUUpwY6eUKen7tr2ZVxTtqp8zlN7482Nyl88yIfQ+qOv34 os5NmFGC7znJJZ0Ewvog78SjRRWdMpi6y1xPOkE5RsKOzf6vQgrqte65RoZuoiFrN8ZKrWTzA0RMW psHf4847ITEdAzRytDnvrMbGD4gEeL83JfC3K3ACBwPKcnptghtEP+qbEouTNZtn5OKtl8+WDnGx8 0hmwgs3Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eLgwB-0002QI-Mk; Mon, 04 Dec 2017 02:56:55 +0000 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLguQ-0000GK-Rn for linux-arm-kernel@lists.infradead.org; Mon, 04 Dec 2017 02:55:21 +0000 Received: by mail-pg0-x243.google.com with SMTP id o2so7203538pgc.8 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=qNT35dQfKSrxcUBiAzdTABNiI+SwAKtY8s2yAXr5TaJQW5GCh/PvTxgEN/NgFdd0+m l6Cm5iXkglw0XRWtZ3FkD4hoFnq0TciZJmWcwNhQWEjKsD39NP+06ROdROGFEsfTdy/A wpKU2DRJlGOe4cmfnOwd2Sl2UmIrHXCxrr0XXeWaK3wLYwxc0hcUiLUVjZm5W5/0YyK9 PNqWV800XztrexV4Tgj8nz0DFparM7vRlunc4rXp0wpbeqNOTrDubbimSc8QePJ0YfXq 1St64AZWq0liMKC2jxc48SD2SkzheVuhLq+k09AEPITkocjcHFn2Jw/ljqG90F6e6MCw 0Dow== X-Gm-Message-State: AJaThX64yTxKz1bqTZ2jDqMskYWaTGt0898c8M+fFlmT/35gEvn45g5h k+5NGyFr6jnia3yBxUu4poZoLg== X-Google-Smtp-Source: AGs4zMYS1naie2pUmrQne5whVFtyfGE+XiP+mgT66h8rU0huujbq8DbDFHJV3xuMSE7iqtNzUxv2tQ== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171203_185507_309753_0638A56F X-CRM114-Status: GOOD ( 13.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: AKASHI Takahiro , Linus Torvalds , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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) /*