[PATCH] unify pfn_to_page: generic functions

There are 3 memory models, FLATMEM, DISCONTIGMEM, SPARSEMEM.
Each arch has its own page_to_pfn(), pfn_to_page() for each models.
But most of them can use the same arithmetic.

This patch adds asm-generic/memory_model.h, which includes generic
page_to_pfn(), pfn_to_page() definitions for each memory model.

When CONFIG_OUT_OF_LINE_PFN_TO_PAGE=y, out-of-line functions are
used instead of macro. This is enabled by some archs and  reduces
text size.

Signed-off-by: KAMEZAWA Hiroyuki <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Ivan Kokshaysky <[email protected]>
Cc: Russell King <[email protected]>
Cc: Ian Molton <[email protected]>
Cc: Mikael Starvik <[email protected]>
Cc: David Howells <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Cc: Hirokazu Takata <[email protected]>
Cc: Ralf Baechle <[email protected]>
Cc: Kyle McMartin <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Cc: Paul Mundt <[email protected]>
Cc: Kazumoto Kojima <[email protected]>
Cc: Richard Curnow <[email protected]>
Cc: William Lee Irwin III <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Jeff Dike <[email protected]>
Cc: Paolo 'Blaisorblade' Giarrusso <[email protected]>
Cc: Miles Bader <[email protected]>
Cc: Chris Zankel <[email protected]>
Cc: "Luck, Tony" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
KAMEZAWA Hiroyuki 2006-03-27 01:15:25 -08:00 • committed by Linus Torvalds
commit a117e66ed4
4 changed files with 121 additions and 11 deletions

View file

@ -2745,3 +2745,45 @@ void *__init alloc_large_system_hash(const char *tablename,
return table;
}
#ifdef CONFIG_OUT_OF_LINE_PFN_TO_PAGE
/*
* pfn <-> page translation. out-of-line version.
* (see asm-generic/memory_model.h)
*/
#if defined(CONFIG_FLATMEM)
struct page *pfn_to_page(unsigned long pfn)
{
return mem_map + (pfn - ARCH_PFN_OFFSET);
}
unsigned long page_to_pfn(struct page *page)
{
return (page - mem_map) + ARCH_PFN_OFFSET;
}
#elif defined(CONFIG_DISCONTIGMEM)
struct page *pfn_to_page(unsigned long pfn)
{
int nid = arch_pfn_to_nid(pfn);
return NODE_DATA(nid)->node_mem_map + arch_local_page_offset(pfn,nid);
}
unsigned long page_to_pfn(struct page *page)
{
struct zone *zone = page_zone(page);
return (page - zone->zone_mem_map) + zone->zone_start_pfn;
}
#elif defined(CONFIG_SPARSEMEM)
struct page *pfn_to_page(unsigned long pfn)
{
return __section_mem_map_addr(__pfn_to_section(pfn)) + pfn;
}
unsigned long page_to_pfn(struct page *page)
{
long section_id = page_to_section(page);
return page - __section_mem_map_addr(__nr_to_section(section_id));
}
#endif /* CONFIG_FLATMEM/DISCONTIGMME/SPARSEMEM */
EXPORT_SYMBOL(pfn_to_page);
EXPORT_SYMBOL(page_to_pfn);
#endif /* CONFIG_OUT_OF_LINE_PFN_TO_PAGE */