[RFC 5/7] mm/memremap: Export pfn_first, pfn_end, find_pagemap functions

Anshuman Khandual khandual at linux.vnet.ibm.com
Tue May 3 16:29:24 AEST 2016


This change exports two existing functions pfn_first, pfn_end and also
defines a new one called find_pagemap. These functions are required to
navigate through the memory which is hotplugged into the ZONE_DEVICE as
device memory.

Signed-off-by: Anshuman Khandual <khandual at linux.vnet.ibm.com>
---
 include/linux/memremap.h | 18 ++++++++++++++++++
 kernel/memremap.c        | 15 +++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/include/linux/memremap.h b/include/linux/memremap.h
index bcaa634..b193044 100644
--- a/include/linux/memremap.h
+++ b/include/linux/memremap.h
@@ -28,11 +28,29 @@ void vmem_altmap_free(struct vmem_altmap *altmap, unsigned long nr_pfns);
 
 #if defined(CONFIG_SPARSEMEM_VMEMMAP) && defined(CONFIG_ZONE_DEVICE)
 struct vmem_altmap *to_vmem_altmap(unsigned long memmap_start);
+struct page_map *find_pagemap(resource_size_t phys);
+unsigned long pfn_first(struct page_map *pgmap);
+unsigned long pfn_end(struct page_map *pgmap);
 #else
 static inline struct vmem_altmap *to_vmem_altmap(unsigned long memmap_start)
 {
 	return NULL;
 }
+
+static inline struct page_map *find_pagemap(resource_size_t phys)
+{
+	return NULL;
+}
+
+unsigned long pfn_first(struct page_map *pgmap)
+{
+	return 0;
+}
+
+unsigned long pfn_end(struct page_map *pgmap)
+{
+	return 0;
+}
 #endif
 
 /**
diff --git a/kernel/memremap.c b/kernel/memremap.c
index a6d3823..3c21051 100644
--- a/kernel/memremap.c
+++ b/kernel/memremap.c
@@ -207,7 +207,7 @@ static void pgmap_radix_release(struct resource *res)
 	mutex_unlock(&pgmap_lock);
 }
 
-static unsigned long pfn_first(struct page_map *page_map)
+unsigned long pfn_first(struct page_map *page_map)
 {
 	struct dev_pagemap *pgmap = &page_map->pgmap;
 	const struct resource *res = &page_map->res;
@@ -220,7 +220,7 @@ static unsigned long pfn_first(struct page_map *page_map)
 	return pfn;
 }
 
-static unsigned long pfn_end(struct page_map *page_map)
+unsigned long pfn_end(struct page_map *page_map)
 {
 	const struct resource *res = &page_map->res;
 
@@ -262,6 +262,17 @@ struct dev_pagemap *find_dev_pagemap(resource_size_t phys)
 	return page_map ? &page_map->pgmap : NULL;
 }
 
+struct page_map *find_pagemap(resource_size_t phys)
+{
+	struct page_map *page_map;
+
+	rcu_read_lock();
+	page_map = radix_tree_lookup(&pgmap_radix, phys >> PA_SECTION_SHIFT);
+	rcu_read_unlock();
+
+	return page_map;
+}
+
 /**
  * devm_memremap_pages - remap and provide memmap backing for the given resource
  * @dev: hosting device for @res
-- 
1.8.3.1



More information about the Linuxppc-dev mailing list