From: Andy Whitcroft The code to convert an address within the vmemmap to the start of the section is currently implemented using macros. Convert these over to a new helper function, clarifying the code and gaining type checking. Signed-off-by: Andy Whitcroft Cc: Christoph Lameter Cc: Dave Hansen Cc: Paul Mackerras Cc: Benjamin Herrenschmidt Signed-off-by: Andrew Morton --- arch/powerpc/mm/init_64.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff -puN arch/powerpc/mm/init_64.c~ppc64-sparsemem_vmemmap-support-vmemmap-ppc64-convert-vmm_-macros-to-a-real-function arch/powerpc/mm/init_64.c --- a/arch/powerpc/mm/init_64.c~ppc64-sparsemem_vmemmap-support-vmemmap-ppc64-convert-vmm_-macros-to-a-real-function +++ a/arch/powerpc/mm/init_64.c @@ -185,14 +185,19 @@ void pgtable_cache_init(void) #ifdef CONFIG_ARCH_POPULATES_SPARSEMEM_VMEMMAP /* - * Convert an address within the vmemmap into a pfn. Note that we have - * to do this by hand as the proffered address may not be correctly aligned. + * Given an address within the vmemmap, determine the pfn of the page that + * represents the start of the section it is within. Note that we have to + * do this by hand as the proffered address may not be correctly aligned. * Subtraction of non-aligned pointers produces undefined results. */ -#define VMM_SECTION(addr) \ - (((((unsigned long)(addr)) - ((unsigned long)(vmemmap))) / \ - sizeof(struct page)) >> PFN_SECTION_SHIFT) -#define VMM_SECTION_PAGE(addr) (VMM_SECTION(addr) << PFN_SECTION_SHIFT) +unsigned long __meminit vmemmap_section_start(struct page *page) +{ + unsigned long offset = ((unsigned long)page) - + ((unsigned long)(vmemmap)); + + /* Return the pfn of the start of the section. */ + return (offset / sizeof(struct page)) & PAGE_SECTION_MASK; +} /* * Check if this vmemmap page is already initialised. If any section @@ -204,7 +209,7 @@ int __meminit vmemmap_populated(unsigned unsigned long end = start + page_size; for (; start < end; start += (PAGES_PER_SECTION * sizeof(struct page))) - if (pfn_valid(VMM_SECTION_PAGE(start))) + if (pfn_valid(vmemmap_section_start(start))) return 1; return 0; _