[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180704041038.8190-4-bhe@redhat.com>
Date: Wed, 4 Jul 2018 12:10:37 +0800
From: Baoquan He <bhe@...hat.com>
To: linux-kernel@...r.kernel.org, akpm@...ux-foundation.org,
robh+dt@...nel.org, dan.j.williams@...el.com,
nicolas.pitre@...aro.org, josh@...htriplett.org,
fengguang.wu@...el.com, bp@...e.de, andy.shevchenko@...il.com
Cc: patrik.r.jakobsson@...il.com, airlied@...ux.ie, kys@...rosoft.com,
haiyangz@...rosoft.com, sthemmin@...rosoft.com,
dmitry.torokhov@...il.com, frowand.list@...il.com,
keith.busch@...el.com, jonathan.derrick@...el.com,
lorenzo.pieralisi@....com, bhelgaas@...gle.com, tglx@...utronix.de,
brijesh.singh@....com, jglisse@...hat.com, thomas.lendacky@....com,
gregkh@...uxfoundation.org, baiyaowei@...s.chinamobile.com,
richard.weiyang@...il.com, devel@...uxdriverproject.org,
linux-input@...r.kernel.org, linux-nvdimm@...ts.01.org,
devicetree@...r.kernel.org, linux-pci@...r.kernel.org,
ebiederm@...ssion.com, vgoyal@...hat.com, dyoung@...hat.com,
yinghai@...nel.org, kexec@...ts.infradead.org, monstr@...str.eu,
davem@...emloft.net, chris@...kel.net, jcmvbkbc@...il.com,
gustavo@...ovan.org, maarten.lankhorst@...ux.intel.com,
seanpaul@...omium.org, linux-parisc@...r.kernel.org,
linuxppc-dev@...ts.ozlabs.org, Baoquan He <bhe@...hat.com>
Subject: [PATCH v6 3/4] resource: add walk_system_ram_res_rev()
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 code.
Signed-off-by: Baoquan He <bhe@...hat.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Brijesh Singh <brijesh.singh@....com>
Cc: "Jérôme Glisse" <jglisse@...hat.com>
Cc: Borislav Petkov <bp@...e.de>
Cc: Tom Lendacky <thomas.lendacky@....com>
Cc: Wei Yang <richard.weiyang@...il.com>
---
include/linux/ioport.h | 3 +++
kernel/resource.c | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index b7456ae889dd..066cc263e2cc 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -279,6 +279,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 6d647a3824b1..4c5fbef4ea24 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -23,6 +23,8 @@
#include <linux/pfn.h>
#include <linux/mm.h>
#include <linux/resource_ext.h>
+#include <linux/string.h>
+#include <linux/vmalloc.h>
#include <asm/io.h>
@@ -443,6 +445,44 @@ int walk_system_ram_res(u64 start, u64 end, void *arg,
}
/*
+ * This function, being a variant of walk_system_ram_res(), calls the @func
+ * callback against all memory ranges of type System RAM which are marked as
+ * IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY in reversed order, i.e., from
+ * higher to lower.
+ */
+int walk_system_ram_res_rev(u64 start, u64 end, void *arg,
+ int (*func)(struct resource *, void *))
+{
+ unsigned long flags;
+ struct resource *res;
+ int ret = -1;
+
+ flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
+
+ read_lock(&resource_lock);
+ list_for_each_entry_reverse(res, &iomem_resource.child, sibling) {
+ if (start >= end)
+ break;
+ if ((res->flags & flags) != flags)
+ continue;
+ if (res->desc != IORES_DESC_NONE)
+ continue;
+ if (res->end < start)
+ break;
+
+ if ((res->end >= start) && (res->start < end)) {
+ ret = (*func)(res, arg);
+ if (ret)
+ break;
+ }
+ end = res->start - 1;
+
+ }
+ read_unlock(&resource_lock);
+ return ret;
+}
+
+/*
* This function calls the @func callback against all memory ranges, which
* are ranges marked as IORESOURCE_MEM and IORESOUCE_BUSY.
*/
--
2.13.6
Powered by blists - more mailing lists